Adsense 728 * 15

Search

Custom Search

For Loop in Java




For Loop in Java


For loop


The for loop repeats a set of statements a certain number of times until a condition is matched. It is commonly used for simple iteration. The for loop appears as shown below.


Syntax of for loop-


for (initialization ; test expression; increment/decrement)
{
             //body of loop
}


In the first part of for loop variable is initialized to a value.


2. In the second part test expression is evaluated which returns Boolean value. 


3. The last part is evaluated every time the loop is executed. 


Example of For loop


class forloop
{
public static void main(String args[])
{
int i;
for (i=0;i<5;i++)
{
System.out.println("\nHi how are you ");
}
}
}


Hi how are you printed five times.


Output


Hi how are you
Hi how are you
Hi how are you
Hi how are you
Hi how are you


No comments:

Post a Comment