Previous
For Loop 
Next
Function 
ABC of JavaScript : An Interactive JavaScript Tutorial
While Loop

While Loop

Syntax :
while(CONDITION) {
BODY
}

This loop will continuously execute the statements in the body as long as a given condition is true. This loop must be handled with care. Always make sure that the given condition will be met - or this loop will continue forever. Let us see an example with the while loop that uses while loop in a situation very similar to the one given in the for loop example.

This basically displays all the elements in an array - the same thing we did using the for loop. Notice how the while loop differs from the for loop. In the while loop, only the condition will be given inside the while loops parenthesis - '(' and ')'.

Previous
For Loop 
Next
Function 
blog comments powered by Disqus