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. Value Types
  3. true, false
  4. Operators
  5. Variable
  6. if then else
  7. for while do Loop
  8. Array Basics
  9. Object Basics
  10. RegExp Tutorial
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 Basics
  4. JS in Depth
  5. JS Reference
  6. DOM
  7. SVG
  8. JS Misc