</>
Skip to content
Java lessons (17/47)

Java — For Loop

Basic for

for (int i = 0; i < 5; i++) {
    System.out.println(i);
}

Enhanced for (for-each)

int[] nums = {1, 2, 3, 4, 5};
for (int num : nums) {
    System.out.println(num);
}

Nested loops

for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        System.out.println(i + ", " + j);
    }
}

Mini Practice

  1. Write for loop
  2. Use for-each
  3. Create nested loops
  4. Practice counting

Up Next

Continue with Break Continue - Loop control.

Related Topics

Frequently Asked Questions about For Loop

What is For Loop in Java?

For Loop is a fundamental concept in Java. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn For Loop?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn For Loop.

Why is For Loop important in Java?

For Loop is essential for Java development. Understanding this concept will help you write better code and solve real-world problems more effectively.