The while and do while loops in JavaScript

The while loop in JavaScript:

If you want to do one thing more and more time in a programme at this time you can do it by conditional statements like “else if” and “switch” but that will be very complicated so you have to use loop statements.

In JavaScript you have “while loop” to do something over and over when the condition of your loop is true.

Syntax:

 Example:

The do while loop in JavaScript:

The do while loop is same as while loop but the difference is that the condition will be checked at the end of the loop. So that the loop always executed at least one time.

 Syntax:

Example:

 

Leave a Reply

Your email address will not be published. Required fields are marked *