While Loop In JavaScript

While Loop in JavaScript
In JavaScript, while loops loop through a block of code until the specified condition is true. The condition is evaluated before executing the statement. The syntax of the while loop is very similar to if statement.Syntax while (condition) { // execute this code as long as the condition is true }
Infinite Loop using While in JavaScript
You might have already the idea what Infinite loop is because of its name. An infinite loop is a loop that will keep running forever. If you make an infinite loop by accident it can crash your browser. So it is really important the awareness of infinite loop otherwise can crash your computer or browser. Look at the example of the infinite loop.// Start a infinite loop while (true) { // execute code forever }
Do While Loop in JavaScript
We have learned upside about while loop. The while loop will run a block of code until the specified condition is true. Do..while statement is slightly different from while statement, it evaluates the condition at the end of each loop irritation. And do...while condition always executes once even if the condition is never true.Syntax
do {
// execute code
} while (condition);
×
![]()































































