learn the first code lrnf blog
ExceptionalDev
March 13, 2025
Comments (3)

learn the first code lrnf blog

The do while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.

const cars = ["BMW", "Volvo", "Saab", "Ford"];
let i = 0;
let text = "";

while (cars[i]) {
  text += cars[i];
  i++;
}

You have already seen the break statement used in an earlier chapter of this tutorial. It was used to "jump out" of a switch() statement.


The break statement can also be used to jump out of a loop:


const cars = ["BMW", "Volvo", "Saab", "Ford"];
list: {
  text += cars[0] + "<br>";
  text += cars[1] + "<br>";
  break list;
  text += cars[2] + "<br>";
  text += cars[3] + "<br>";
}

Tags:

#css#javascript

RECENT BLOGS: