Java Tutorial · Chapter 9 of 12
Java For Loop
Counted loops.
for loops are ideal when you know how many times to repeat.
They are also the default tool for walking through arrays.
For sample
Try it Yourself »
public class Main {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}
}
}
Classroom Tips
- Check whether you need <= or <.