Powered by Blogger.
Showing posts with label for loop syntax. Show all posts
Showing posts with label for loop syntax. Show all posts

Java | For Loop Statement Program in java

For Loop Statement:

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.

A for loop is useful when you know how many times a task is to be repeated.

for loop syntax:

for(initialization; condition; increment/decrement){
        statements;
}

For Loop Program:

public class Test {

   public static void main(String args[]) {

      for(int x = 20; x < 30; x = x + 1) {
         System.out.print("value of x : " + x );
         System.out.print("\n");
      }
   }
}

Output:
value of x : 20
value of x : 21
value of x : 22
value of x : 23
value of x : 24
value of x : 25
value of x : 26
value of x : 27
value of x : 28
value of x : 29