Lecture notes Wednesday 2/3/99
if, if else, while
- control structures:
- sequential execution vs. transfer of control
- "goto statement considered harmful"
- 3 control structures: sequence, selection and repetition structure
- selection: if (single), if/else (double), switch (multiple)
- repetition/ loop: while, do/while, for
- put together: stacking or nesting
- flowcharts:
- graphical representation of control structures of an algorithm
- symbols: oval (beginning or end), rectangle (action), diamond (decision), small circles (connectors); flowlines/ arrows
- if selection structure:
- no action if condition does not hold
- use { and } if action consists of several statements (compound statement)
- if/else selection structure:
- different action if condition does not hold
- nested if/else structure: else refers to last if, triggers only once
- while repetition structure:
- action is to be repeated while some condition remains true
- syntax: while (condition) statement
- counter-controlled (definite) repetition
- sentinel-controlled (indefinite) repetition
- nested control structures
- assignment operators
- abbreviate arithmetic assignment expressions
- increment & decrement operators
- prefix (done before) vs. postfix (done after)
- doesn't matter if statement by itself