Conditional Statements
For computer to make decisions, must be able
to test CONDITIONS
IF it is raining
THEN I will not go outside
IF Count is not zero
THEN the Average is Sum divided by Count
Conditions specified using logical data
, Loops
• For
• While
• Do While
, IF Statement
• Syntax: if (LogicalExpr) Statement
• Program context:
statement1;
if (LogicalExpr) statement2;
statement3;
• Order of execution:
LogicalExpr
1 (true) 0 (false)
statement1 statement1
statement2 statement3
statement3
, Flow of Execution
For computer to make decisions, must be able
to test CONDITIONS
IF it is raining
THEN I will not go outside
IF Count is not zero
THEN the Average is Sum divided by Count
Conditions specified using logical data
, Loops
• For
• While
• Do While
, IF Statement
• Syntax: if (LogicalExpr) Statement
• Program context:
statement1;
if (LogicalExpr) statement2;
statement3;
• Order of execution:
LogicalExpr
1 (true) 0 (false)
statement1 statement1
statement2 statement3
statement3
, Flow of Execution