Loops

suggest change

Syntax

Remarks

Loops in JavaScript typically help solve problems which involve repeating specific code x amount of times. Say you need to log a message 5 times. You could do this:

console.log("a message");
console.log("a message");
console.log("a message");
console.log("a message");
console.log("a message");

But that’s just time-consuming and kind of ridiculous. Plus, what if you needed to log over 300 messages? You should replace the code with a traditional “for” loop:

for (var i = 0; i < 5; i++){
    console.log("a message");
}

Standard for loops

for ... of loop

for ... in loop

while loops

continue loop

Break specific nested loops

do ... while loop

break and continue labels

break out of a loop

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents