The for loop

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)

Answer these questions about For loops  

1. How do you increment a variable called num?

2. How many times will this loop print the word "hello"?
for ( int h=0; h<3;h++){

3. What is the missing number if I want this loop to repeat 5 times?
for( int j = 0; j < _____; j++)

4. The 3 parts of a for loop are initialize, increment and

Click Submit and then , if you need a record of your results, hold down Alt and press Prnt Scrn to get a screenshot.