For loop provides a concise way of writing the loop structure. Unlike a while loop, a for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.
The simple for loop is same as C/C++. We can initialize variable, check condition and increment/decrement value.
for (initialization; condition; increment/decrement)
{
//your statement
}
public class ForLoopDemo {
public static void main(String[] args) {
for(int i=1;i<=10;i++){
System.out.println(i);
}
}
}
1
2
3
4
5
6
7
8
9
10
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning