JavaScript Using While Loop

One of the most used loops in JavaScript is the While loop.

The purpose of the while loop is to repeatedly execute the code block as long as the expression (condition) is true. The loop terminates when the expression is false.

The use of the loop is the same as in many programming languages.

while (condition) {
Code to run if condition is true
}

Let's examine the example below..

In the example, as long as our num variable is less than 5 , it will loop and the code inside will run. The result will be as follows.



You May Interest

What are Asynchronous Scripts in Javascript ?

What is Promise in Javascript ?

What is setInterval Function in Javascript ?

What are Deferred Scripts in Javascript ?

JavaScript Making Uppercase