Java for Loop:
We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it. |
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times. It is useful when you know how many times a task is to be repeated. It is used for a fixed number of iterations.
Java for Loop Syntax:
for (initialization; Condition; update) { // Statements; } |

public class For_loop {
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int x=5; x<=12; x++) {
System.out.println(x);
}
}
}

public class For_loop {
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int x=12; x>=5; x--) {
System.out.println(x);
}
System.out.println("Code Works Successfully");
}
}
Comments (No)