JS: for while do Loop

By Xah Lee. Date: . Last updated: .

“for” Loop

for (let i=0; i < 9; i++) { console.log(i); }

See also:

“while” Loop

let x = 0;
while (x !== 5) { console.log(x); x++;} // prints 0 to 4

“do…while” Loop

let x = 0;
do { console.log(x); x++} while (x !== 5) // prints 0 to 4

“continue”, “break”

for (let i=0; i <= 5; i++) {
    if (i===3) {continue;}       // skip 3
    console.log(i);
}                               // prints 0 to 5, but not 3
for (let i=0; i < 5; i++) {
    console.log(i);
    if (i===3) {break;}
}                               // prints 0 to 3

JavaScript Basics

  1. JavaScript Basics
  2. true, false
  3. Operators
  4. Branch Control
  5. Loop
  6. Array Basics
  7. Object Basics
  8. RegExp Basics
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog