Java-For Loop

For Loop

The for loop is usually used when the number of iterations is predetermined. The format of the for loop is :

First executed expression1 is only once before looping, then executed expression2,  expression2 is a conditional or boolean expression, if the condition is true, then the body of the statements is executed. After execution of the body, expression3 is executed. After execution of the expression3, expression2(conditional or boolean) is evaluated ones again, and if it is true, the body of statements is executed once again. This process of repeated execution of the continues until the condition finally becomes false and the loop is terminated.

Program

1

Program Source

class Javaapp {

    public static void main(String[] args) {
        
        for(int i=0;i<5;i++)
        {
            System.out.println("Value of i = "+i);
        }
        
    }
}

Leave a Comment