Mask-group

For Loop



  • The general form of for loop is:

for(initialize counter; test counter ; increment counter){

do this;

and this;

and this;

}

  • The for loop allow us to specify three things about loop in a single line:
  1. Setting a loop counter to an initial value.
  2. Testing the loop counter to determine whether its value has reached the number of repetitions desired.
  3. Increasing the value of loop counter each time the program segment within the loop has been executed.
  • Note: The initialization,testing and incrementation part of the for loop can be replaced by any valid expression.

  • Example