CS 120     Jeff Horn                

While Loops in Java 

 

int i;    //  Declare i to be an integer.   This will be our "loop index variable", a.k.a., "loop counter variable"

i = 0;       //  Initialize our loop counter to 0.   "i" always indicates how many times we have been executed the loop body.

while( i < 67)               //  This is the boolean (true/false) condition.   While it is true, we execute the body of the loop, below.  
                                   // Do NOT put any semi-colon here!  
                                   // Also, no space, please, between the word "while" and the left parenthesis.
   {                              //   The body of the loop is the code between curly braces.
                                   // loop body code goes here; whatever you want to do each time through the loop.
                i = i + 1;      // You must increment "i" somehow, or loop condition will never become false!
    }                             //  Don't forget to close off your loop body!