Learn Java , Selenium

For Loop in Java – 

				
					package practice;

public class ForLoop {

	public static void main(String[] args) {
		
		for (int i = 0; i <= 5; i++ ) {
			  System.out.println(i);
		}

	}

}

				
			

Explanation

The for loop has three parts:

for (initialization; condition; update)

In our code:

  • int i = 0;Initialization: Start from 0

  • i <= 5;Condition: Loop will continue as long as i is less than or equal to 5

  • i++Update: Increase i by 1 after each loop

➡️ The loop runs 6 times (from 0 to 5).

 Output- 

   0
   1
   2
   3
   4
   5

Scroll to Top