This loop will execute until the condition is given false.
Syntax:-
while(condition){
// logic implement
}
Example:- Now, you have to print the i value until the i value not more than 20.
var i=0;
while(i<=20){
console.log(i);
i++;
}
Output:-
0
1
.
.
0
1
.
.
19
20
Example:- Now, you have to print the even i value until the i value not more than 10.
var i=2;
while(i<=10){
if(i%2 ==0){
console.log(i);
}
i++;
}
Output:-
2
4
6
8
10
2
4
6
8
10