The most basic type of looping in JavaScript is the while
loop. A while
loop tests an expression and continues to execute the code contained in its {}
brackets until the expression evaluates to false
.
For example, the following while
loop executes until i
is equal to 5
:
var i = 1;
while (i<5){
console.log("Iteration " + i);
i++;
}
This example sends the following output to the console:
Iteration 1
Iteration 2
Iteration 3
Iteration 4