java for loop example program

java for loop which executes group of statements repeatedly until a particular condition is true.
java for loop structure
for(initialization:condition/expression;increment/decrement){
//group of statements
}

initialization
  • the initialization expression initializes the loop means we will declare ad perform the initialization for the varialbles.
  • the initialization section will be executed only once. and in this section we can declare multiple variables of same data type.
condition/expresion
  • we can take any java expression as condition and here result should be boolean type. when the condition fails the for loop will terminate.
Increment/decrement
  • the increment/decrement section is invoked after each iteration of loop inthissectiin we will increment or decrement the variable value.

Example

public class ForLoopDemo{
public static void main(String[] args){
for(int i = 0;i<=15;i++){
System.out.println("The Integer count is :"+i);
}
}
}

output