A while loop is a conditional loop in which the condition is checked at the beginning of the loop, and if the condition is true, the statement in the loop is executed. Therefore, the required changes in the condition must be inside the statement, otherwise the loop may loop indefinitely. In order to facilitate understanding, we can say While True Loop. This means that as long as the expression is to go to the loop.

You can also see the PHP while loop, where ASP will loop with more or less similar goals and a somewhat similar syntax.

Here is the basic syntax of the while loop in JavaScript.

while ( expression )
{
statements; 
}

Note that the expression here is checked or evaluated before the loop starts, so if the condition returned is FALSE, the loop will not be executed.

Let’s try this printing example

var i=0;
while (i <= 5)
{
document.write(i+"<br>")
i++;
}

Use break
We can use the break statement in the while loop to exit the loop. here is

var i=0;
while (i <= 5)
{
document.write(i+"<br>")
if(i>2){break;}
i++;
}

Do the while loop
Do While loops are slightly different from while loops. Here, the condition is checked at the end of the cycle. So even if the expression is FALSE, then once the statement in the loop will be executed. This is the basic difference between a do while loop and a while loop. Here is an example of a Do While loop in JavaScript.

var i=0;
do
{
document.write(i+"<br>")
i++;
} while (i <= 5)

In the above code, the condition is checked only at the end of the loop. Here you can also use the break statement from the loop out. Here is an example

var i=0;
do
{
document.write(i+"<br>")
if(i>2){break;}
i++;
} while (i <= 5)

Use a while loop and a for loop to develop such a pattern:
*
**
***
****
*****
******