Java


Java Tutorial


Admission Enquiry Form

  

For Loop in Java

What is For loop in Java?

For loop is a known loop in Java.It is used for the repetition of statements.

Syntax of For loop

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




Example of for loop:

//Java program of for loop
public class ForLoop {
public static void main(String[] args)
{
int num;
for(num=1;num<=5;num++)
{
System.out.println("Compuhelp");
}//end of for loop
}//end of main method
}//end of class ForLoop


Compuhelp
Compuhelp
Compuhelp
Compuhelp
Compuhelp

In the above example, this for loop will print Compuhelp 5 times.