The for loop is the type of looping construct. It also works as while loop construct but it provide the initialization, condition and the increment is same written in the for construct. All the statements which has to be executed written in the for block
The Syntax for the For Loop:
for( initialization; termination; increment)
{
statements;
}
{
statements;
}
Example
public class ForLoop {
public static void main(String[] args) {
for(int i = 1;i <= 5;i++) {
System.out.print(i);
}
}
}
No comments:
Post a Comment