Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Basics : do/while Loop

Monday, October 4, 2021

JavaScript Basics : do/while Loop

The do/while loop is similar to the while loop.  The difference is that the first the loop expression is tested after the do statement block is executed at least once.  For example let's use our countdown example again.

If we have the code below the countdown displays the same results as the output.  However, the first iteration is performed without a evaluation of the expression.  It's not until the countdown is 9 that the while part of the loop kicks in.



var countdown = 10;

do {
    console.log(countdown);
    countdown--;
}
while(countdown > 0)

console.log("Happy New Year!");



















2 comments:

  1. Accomplished designers have to work to design a logo and this takes work. To design a logo, you need to invest time and effort. It is not equivalent to just playing on the computer for a few hours.

    ReplyDelete
  2. I feel very happy about & learning more about this blog. Keep sharing your information regularly for my future reference. This content creates a new hope and inspiration within me. Thanks for sharing blog like this. The information which you have provided is better than another blog. JOIN
    ABest blogger sites in india HERE.

    ReplyDelete

Search This Blog