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. How to Run JavaScript
  2. JS: How to Use Browser Console
  3. JavaScript Basics
  4. JS: Data Types
  5. JS: true, false
  6. JS: Operators
  7. JS: Variable
  8. JS: Branch Control: if then else, switch
  9. JS: for while do Loop
  10. JS: Array Basics
  11. JS: Object Basics
  12. JS: RegExp Tutorial
  13. JS: Throw Try Catch Finally
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon