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 is Strict Mode in JavaScript ?

What is Difference Between Undefined and Null in Javascript ?

What are Advantages of Javascript ?

What are Different Error Types in Javascript ?

What is Difference Between Call and Apply Methods in Javascript ?