while in js code example

Example 1: js loop

var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) { 
  console.log(colors[i]);
}

Example 2: javascript while

var i=0;
while (i < 10) {
	console.log(i);
	i++;
}
//Alternatively, You could  break out of a loop like so:
var i=0;
while(true){
	i++;
	if(i===3){
		break;
	}
}

Example 3: do while javascript

do {
  //whatever
} while (conditional);

Example 4: while loops js

while (10 > 1) {
  console.log("HI");
}

Example 5: javascript while loop

while (i < 10) {
  text += "The number is " + i;
  i++;
}

Example 6: javascript while loop

while(condition) {
  //whatever
}

Tags:

Php Example