JS while Loop

Last Updated: March 16, 2022

JS while loop syntax

while (condition) {
  // code block to be executed
}
const numbers = [1, 2, 3, 4, 5];
let i =0;
while(i< array.length) {
    console.log(numbers[i]);
});

do while loop in JavaScript

Block of code will be repeatedly executed until the condition is true

Code will be executed at least one time

do while syntax

do {
  // code block to be executed
}
while (condition);
Test