Executing code block repeatedly in Java using for loop

In Java, a "for loop" is a control structure that allows you to execute code repeatedly depending on a given condition. A typical "for loop" structure has three parts: an initializer, a condition, and an iteration statement. These three parts are separated by a semicolon and enclosed in parentheses immediately after the "for" keyword. A loop begins with an initializer, typically initializing a loop control variable. Next, before each iteration, the condition is checked. If the condition evaluates to true, the code block inside the loop will be executed. After the loop body is executed, an iteration statement is executed, typically incrementing or decrementing the loop's control variable. The loop runs the code block as long as the condition evaluates to true. If the condition is false, the loop ends, and program execution continues with the statement following the loop. In this Java For Loop Example, we execute code block repeatedly using "for loop". Click Execute to run the Java For Loop Example online and see the result.
Executing code block repeatedly in Java using for loop Execute
public class ForLoopExample {
    public static void main(String[] args) {
        for(int i = 1; i <= 5; i++) {
            System.out.println(i);
        }
    }
}
Updated: Viewed: 40 times