CS 101 Notes 10/12/2010 For Loop - a variation on the while loop that combines - the initialization statement - the condition statement - the increament statement onto a single line of code The while loop had the following form: ; while ( ) { ; ; } The for loop that does the the exact same thing as the above while loop has the form: for ( ; ; ) { ; } One more type of loop: do-while loop While loops and for loops check the condition before executing the body. a do-while loop checks the condition after execting the body of the loop. A do-while loop has the following form ; do { ; ; } while ( ) ; The big difference is that the do-while loop executes the one time when the condition is initially false. If Statements: Allow a section of code to be conditionally executed. The most basic form of an if statement is the "if-then" statement. if ( ) { ; } The code in the will only be executed if the is true; // absolute value value = -104; if ( value < 0 ) { value = - value; } System.out.println ("Absolute Value: " + value); The next common form of an if statement is an "if-then-else" statement if ( ) { ; } else { ; } IF the condition is true only the is executed If the condition is false only the is executed int value1, value2, max; value1 = 9; value2 = 3; if ( value1 > value2 ) { max = value1; } else { max = value2; }