Chapter 5
Flow of Control
- So far our flow of control has been liniear
- We are about to learn control structures
- Selection - making a one time decision and executing or skipping statements based upon the decision
- Looping - repeating a series of statements until a condition is met.
- In both cases, we will employ code blocks to group multiple statements into a single statement.
- Review the convention:
- All code within a code block is indented by a standard amount.
- Please note, for control structures, I will expect you to be able to give
- The default syntax
- The prefered use
- A description of the flow of control
- An example of use.
The Bool type
- bool is an integer type, but only two values
- true, false.
- In C it was 0 and not 0
- no real output or input capailities
- Operations: and (&&) , or (||), not(!)
- Do not use the bitwise operations & (and) or | (or)
- Operations that produce booleans ==, !=, <=, < >=, >
- Be careful of = and ==
The If statement
- Two forms
- if ( boolean expression) statement;
- if ( boolean expression) statementA else statementB;
- flow of control