There are 3 types of loop in java:
- For Loop
- While Loop
- Do While Loop
The for loop is used to iterate a part of the program several times. And if the number of the iteration is fixed then it is recommended to use for loop.
The Java for loop consists of four parts:-
- Initialization
- Condition
- Statement
- Increment/Decrement
class Counting { public static void main(String args[]) { int i; for(i=1 ; i<=10 ; i++) { System.out.println(i); } } } Output: 1 2 3 4 5 6 7 8 9 10