Conditional Statement

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

*Syntax: if ( Expression ) Statement
 
*Semantics: The expression must be of type boolean. If it evaluates to true, the given statement is executed, otherwise not.
 
*Note that there is only one statement. To execute more than one statement conditionally, a block statement is to be used.
 
*The Code Conventions by Sun (which belong to our coding standards) require that a block statement is always to be used, independent from the number of statements that are to be executed conditionally.
 
*In addition, our coding standard expects following layout:

if ( Expression ) {
    Statement1
    Statement2
    ...
}

 

BankAccount.java
      string += dollars;
      if (cents != 0) {
         string += ".";
         if (cents < 10) {
            string += "0";
         }
         string += cents;
      }

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