Conditional Statement II

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*Syntax: if ( Expression ) Statement1 else Statement2
 
*Semantics: The expression must be of type boolean. If it evaluates to true, Statement1 is executed, otherwise Statement2.
 
*Again, blocks are to be used to compound several statements into Statement1 or Statement2.
 
*Our coding standard requires following layout:

if ( Expression ) {
    Statement1a
    Statement1b
    ...
} else {
    Statement2a
    Statement2b
    ...
}

 

HiLo.java
         // guess != secretNumber
         if (guess < secretNumber) {
            System.out.println("Too small!");
         } else {
            // guess > secretNumber
            System.out.println("Too large!");
         }

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002