Computer Applications

What is for loop? What are the parameters used in for loop?

Java Iterative Stmts

46 Likes

Answer

The for loop is used when number of iterations is fixed and known. It is also referred to as a fixed or known iterative looping construct.

The following parameters are commonly used in a for loop:

  1. An initial value for the loop control variable.
  2. A condition—loop will iterate as long as this condition remains true.
  3. An update expression to modify the loop control variable after every iteration.
  4. Body of the loop which consists of the statements that needs to be repeatedly executed.

Below is an example of for loop, it prints the table of 2 till 12:

for (int i = 1; i <= 12; i++) {
    int a = 2 * i;
    System.out.println("2 x " + i + "\t= " + a);           
}

Answered By

25 Likes


Related Questions