The for loop is a shorthand way to write counter loops. This loop prints the numbers from 0 to 9
for ( count = 0; count < 10; count++ ){ // initialize to 0, test each time to see if you are still less than 10, increment each time System.out.print( count + " " ); }
It does the same thing as this loop built using a while statement:
count = 0; // initialize while ( count < 10 ) // test { System.out.print( count + " "); count++ ; // increment }
The variable count in both loops is the loop control variable. (A loop control variable is an ordinary variable used to control the actions of a looping structure.)
Note: count++ is a shortcut for count = count + 1.
The basic form of a for loop is:
for ( initialize; test; increment)