Executable Statements


[Page 817 (continued)]

Simple statements, such as assignment statements, should be written one per line and should be aligned with the other statements in the block. Compound statements are those that contain other statements. Examples would include if statements, for statements, while statements, and do-while statements. Compound statements should use braces and appropriate indentation to highlight the statement's structure. Here are some examples of how to code several kinds of compound statements:

  if (condition) {                              // A simple if statement       statement1;       statement2;   } // if   if (condition1) {                             // An if-else statement       statement1;   } else if (condition2) {       statement2;       statement3;   } else {       statement4;       statement5;   } // if/else for (initializer; entry-condition; updater) {   // For loop      statement1;      statement2; } // for while (condition) {                             // While statement      statement1;      statement2; } // while do {                                            // Do-while statement      statement1;      statement2; } while (condition); 





Java, Java, Java(c) Object-Orienting Problem Solving
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition)
ISBN: 0131474340
EAN: 2147483647
Year: 2005
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net