while Loops
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 1Iteration 2Iteration 3Iteration 4
Get Learning AngularJS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.