while statement javascript code example
Example 1: javascript while
var i=0;
while (i < 10) {
console.log(i);
i++;
}
var i=0;
while(true){
i++;
if(i===3){
break;
}
}
Example 2: do while javascript
do {
} while (conditional);
Example 3: javascript while loop
while(condition) {
}
Example 4: javascript do while
var result = '';
var i = 0;
do {
i += 1;
result += i + ' ';
}
while (i > 0 && i < 5);
console.log(result);
Example 5: while javascript
do {
text += "The number is " + i;
i++;
}
while (i < 10);