Home >> Javascript >> While loop in Javascript

While loop in Javascript

The while loops through a block of code when condition is true.

Syntax

while (condition) {
    // Code to be executed;
}

Example

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

Output

1

2

3

4

5

Post Your Comment

Next Questions
Do while loop
Functions
Objects
Array
Events
Onchange event
Onclick event
Onmouseover event
Onmouseout
Onkeydown event
Onload event

Copyright ©2022 coderraj.com. All Rights Reserved.