September 2015
Intermediate to advanced
92 pages
1h 30m
English
CHAPTER 7
![]()
Loops
The loop statements are used to execute a code block several times. JavaScript has four kinds of loops: while, do-while, for, and for-in. As with the conditional if statement, the curly brackets for these loops can be omitted if there is only one statement in the code block.
While Loop
The while loop runs through the code block only if its condition is true, and will continue looping for as long as the condition remains true.
var i = 0;while (i < 10) { document.write(i++); // 0-9}
The loop here will print out the numbers 0 to 9. Bear in mind that the condition is only checked at the start of each iteration.
Do-While Loop
The ...
Read now
Unlock full access