Flow of Control
Default Flow of Control (p. 44)
Method Call and Return (Ch. 2.3.7)
(perhaps we will look at trace of CyberPet example from Ch. 2.3.8, using
BlueJ's debugger)
if statement (Ch. 3.6.1)
syntax:
if ( boolean expression )
statement;
or with compound statement:
if ( boolean expression ) {
compound statement
}
Note that the compound statement can itself include a (nested)
if statement
if-else statement (Ch. 3.6.2)
syntax:
if ( boolean expression )
statement1;
else
statement2;
pitfall: the dangling else (Ch. 3.6.4)
How would the following be interpretted:
if (condition1)
if (condition2)
System.out.println("One");
else
System.out.println("Two");
switch statement
Michael Goldwasser
Last modified: Wednesday, 11 February 2004