JavaScript Loops
The For Loop
Loops can execute a block of code a number of times. The for
loop is the most common loop.
for (expression 1; expression 2; expression 3) {
// code block to be executed
}
The While Loop
The while loop loops through a block of code as long as a
specified condition is true.
Do...While Loop
The do...while loop is a variant of the while loop.
This loop will execute the code block once, before checking if the
condition is true, then it will repeat the loop as long as the
condition is true.
Break and Continue
The break statement "jumps out" of a loop.
The continue statement "jumps over" one iteration
in the loop.
Summary
for- loops through a block of code a number of timeswhile- loops through a block of code while a specified condition is truedo...while- also loops through a block of code while a specified condition is truebreak- exits the loopcontinue- skips the current iteration and continues with the next
Quick Quiz
Which statement skips the current iteration of a loop?
Enjoying these tutorials?