xxxxxxxxxx
let i=5;
do {
console.log(i);
i++;
}
while (i<5);
xxxxxxxxxx
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;
}
}
xxxxxxxxxx
const numbers = [3, 4, 8, 9, 2];
let number = 0;
while (number < numbers.length) {
const getNumbers = numbers[number];
console.log(getNumbers)
number++
}
//Expected output:3 4 8 9 2
xxxxxxxxxx
//Joke: A programmers wife tells him: "While you're at the store, get some milk.
//...He never comes back...
var endOfCondition = 1;
var someCondition = true;
while(someCondition === true){
console.log("Executing code " + endOfCondition + " times.")
if(endOfCondition == 20)
{
someCondition = false;
}
endOfCondition++;
console.log(endOfCondition - 1)
}
xxxxxxxxxx
const ourArray = [];
let i = 0;
while (i < 5) {
ourArray.push(i);
i++;
}
xxxxxxxxxx
var i = 1; // initialize
while (i < 100) { // enters the cycle if statement is true
i *= 2; // increment to avoid infinite loop
document.write(i + ", "); // output
}
xxxxxxxxxx
let cupsOfSugarNeeded = 8; //Specific amount of cups needed
let cupsAdded = 0; //Initialize the cups to zero
do {
cupsAdded ++; //Add sugar one at a time
} while (cupsAdded < cupsOfSugarNeeded); //Keep adding while the cups is less than the amount needed