let cupsOfSugarNeeded = 3;
let cupsAdded = 0;
do {
cupsAdded++;
console.log(cupsAdded);
} while (cupsAdded < cupsOfSugarNeeded) {
}
The problem is that when I add console.log to the “do” part of the loop it prints 1, 2 and 3 as it should. But when I put it in the “while” part, it just prints 3. Shouldn’t it print 1, 2 and 3 as well?
const cupsOfSugarNeeded = 3;
let cupsAdded = 0;
do {
cupsAdded++;
console.log(`I've added ${cupsAdded} cups of sugar so far.`)
} while (cupsAdded < cupsOfSugarNeeded){
console.log("Hello.");
console.log("The code in this block runs independently from the loop.\nThe looped code is inside the 'do' block.\nPutting curly braces around this code is inconsequential\nunless you define a block scoped variable inside the block.\nThe variable won't be accessible outside of the block.");
}
{
console.log("Same with this block.");
const blah = 10;
}
//Uncommenting the next line will throw a reference error since blah is not defined in this scope
//console.log(blah);