JAVA while loop

while loop is the simplest form of loop, and it is entry controlled loop statement.

Syntax:

while(test condition)

{

Body of loop

}

At the first, condition is evaluated and if it is true then the body of loop is executed and then again the condition is evaluated and if it is true then the body of loop executed again.  This process goes again and again until the condition is not false. If the condition goes false then the control is exit out of loop.

 

e.g:     

while(a<5)

{

System.out.println(“java”);

a=a+1;

}

Let suppose ‘a’ is initialized at 1 then it will print ‘java’ four times.

Leave a Reply

Your email address will not be published. Required fields are marked *