Javascript for and while loop

Javascript for loop has the following syntax.

for (statement 1; statement 2; statement 3) {
        the code block
}

Statement number 1 is where we will initiate a value before the loop starts. Statement 2 defines the condition for running the loop. Statement 3 is where we increase the initial value. In below example we will show the alert function 10 times with the for loop.

for (var i=0; i<10; i++)
{
   alert("Hi");
}

The below alert box will continue to show as long as the condition is true.

while (true)
{
   alert("hey");
}

The above while loop will run forever until the computer is running out of resources and the browser will be forced to shut down.