- Basic form of conditional control flow.
if (boolean-expression)
statement1
else
statement2
- Example
class IfElse1 {
public static void main (String[] args) {
int i = 10;
if ( i==1 )
System.out.println( "i == 1" );
else if ( i==2 )
System.out.println( "i == 2" );
else if ( i==3 )
System.out.println( "i == 3" );
else
System.out.println( "don't know what 'i' is" );
}
}
Next: switch
Up: Flow control and loops
Previous: Statements and blocks
  Contents
|
|