|
|
Loops - The while Loop Tutorials > JavaScript > Loops - The WHILE Loop
What are Loops?
Often you may need to execute the same block of code several times consecutively. Loops provide a convenient structure in which to do this.
The while Loop
A while loop takes the form:
while (condition) {
//Do something.
}
The condition is a JavaScript statement which evaluates to true or false. A simple example:
var i=0;
while(i<5) {
document.write(i + "<br/>");
i++; //Add 1 to 'i'
}
This produces the output:
1
2 3 4 5 Page Responses
Currently there have been no responses to this page...
If you have anything to contribute to this tutorial, found a bug, or know a better way of achieving the same goal, please leave your response below.
|