Java For Loop Examples

Java For Loop Examples

The for loop is commonly used when the number of iterations is known. Below are multiple practical examples.


📌 Example 1: Print 1 to 10

📌 Output:

1
2
3
4
5
6
7
8
9
10

📌 Example 2: Print Even Numbers

📌 Output:

2
4
6
8
10
12
14
16
18
20

📌 Example 3: Reverse Countdown

📌 Output:

10
9
8
7
6
5
4
3
2
1

📌 Example 4: Multiplication Table


 

📌 Output:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50

📌 Example 5: Sum of First 10 Numbers


 

📌 Output:

Sum = 55

📌 Example 6: Loop Through an Array


 

📌 Output:

BMW
Audi
Tesla

📌 Example 7: Nested For Loop (Pattern)

📌 Output:

*
* *
* * *
* * * *
* * * * *

🧠 Summary

Example TypePurpose
CountingPrint numbers sequentially
Even NumbersIncrement pattern
CountdownReverse iteration
Multiplication TablePattern multiplication
SumAccumulation logic
Array IterationAccess array elements
Nested LoopPrint patterns

You may also like...