This loop continues while the given condition is found true else the loop gets terminated. The variable meets the condition at the gate of while loop if the variable do not fulfill the condition then the loop will not be executed for even a single time.


While (condition ){

code to be executed



do – while

This loop continues while the given condition is found true else the loop gets terminated, the difference in this and while looping is even the condition is false but this loop gets executed at least once but while loop gets terminated at initial level if condition is not satisfying.



code to be executed

}While (condition )



This loop contains the initial value, termination value , increment/decrement value in a single line, which in on other looping are used in separate line, the scope of a for loop is inside the curly brackets used with it. The initialization segment is executed only once at the start of the loop and termination and increment/decrement segments are executed every time till the condition remains true.


for(initialization; termination; increment/decrement){

code to be executed



break and continue

These statements are used with in a loop. Break as the name suggests is used to break or terminate the loop in between & continue is to continue the loop breaking it for current loop value.

This statement breaks the loop & shifts the control out of the loop.

This statement breaks the loop for current value and resumes the loop with new value.

for syntax refer the example…

for - - in

This loop is used with arrays and objects , to access their elements and properties respectively.

In looping the variable starts from zero and increases itself with one until it reach to the length of array.


for( variablename in objectname){

lines to be executed




sample code

<script type="text/javascript">

var count;

if (count<10){
if (count>20){

document.write(" "+count)

var color;
var shop=new Array()
for(color in shop){

document.write("<br> "+shop[color]);


</script >

Understanding program:
Value of count is initially 00 , the condition with for loop is while count is lesser than 100 the statements typed in thebox of for loop should be executed.But because of continue command first 10 digits are not printed and then bcz f break command loop terminates aftr 20.C implementation to understand bettr.

Color is a undefined variable and shop is an array, when color is kept as a subscript of array shop then the color variable becomes of number type and from 0 to 4 gets incremented by for – in loop. It is increased up to 4 only because shop array have 5 elements and an array start from 0 position.

click loop to C above code's implementation in browser…

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.