for loop in java example

We are going to discuss about for loop in java example. The for loop statement has type loop control statement. We first initialize the variable. After that check the condition, if true than it will execute further. If it is false, it will terminate loop.

for loop in java example

We are going to discuss about for loop in java example. The for loop statement has type loop control statement. We first initialize the variable. After that check the condition, if true than it will execute further. If it is false, it will terminate loop.

for loop in java example

for loop in java example

We are going to discuss about for loop in java example. The for loop statement has type loop control statement. We first initialize the variable. After that check the condition, if true than it will execute further. If it is false, it will terminate loop. We initialize condition and the increment is same written in the for term. We use three steps in for loop statement, these are: initialization; termination; increment. The for loop statement is as follows:

  • Syntax

for( initialization; termination; increment)
{
statements;
}

initialization:- It initializes the variable and it allows the variable to be executed like:-

int i=0;

termination:-It allows the certain condition. If this condition is true then it will execute all statement otherwise it will ignore it.

i<5; , i>5; , i<=5; , i>=5;

increment:- It allows increase in the given variable like:

j++;

Example:-

  public class ForLoopExample{
	    public static void main(String [] args){
	        for(int i=0 ; i<5 ; i++)
	        {
	                System.out.println( " ");
	                
	                for(int j=i; j<5; j++){
	                	System.out.print("*");
	                	
	                }
	             }

	         } 
	     }

OutPut

Download Source Code