while do javascript code example

Example 1: 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 2: do while javascript

do {
  //whatever
} while (conditional);

Example 3: while loops js

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

Example 4: while loop js

let count = 0;
let max = 10;
while (count < max) {
	console.log(count)
    count = count + 1
}

Example 5: Iterate with Do While Loops Javascript

var myArray = [];

var i = 10;

 do {  // The do while loop will always run atleast once before checking the condtion. This will return false and break out of the loop.
	myArray.push(i);
    i++;
} while (i < 5)

console.log(i, myArray);

Example 6: javascript do while

var result = '';
var i = 0;
do {
   i += 1;
   result += i + ' ';
}
while (i > 0 && i < 5);
// Despite i == 0 this will still loop as it starts off without the test

console.log(result);