java / beginner
Snippet
The For Loop
A for loop repeats a block of code a specific number of times. It consists of initialization, a condition, and an increment step.
snippet.java
1
2
3
for (int i = 1; i <= 5; i++) {System.out.println("Count: " + i);}
Breakdown
1
int i = 1;
Initializes the loop counter variable 'i' to 1.
2
i <= 5;
The loop continues as long as 'i' is less than or equal to 5.
3
i++
Increases the value of 'i' by 1 after each iteration.