There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
In this example (look bellow) I understand the do…while` statement creates a loop that executes a specified statement until the test condition evaluates to false.
What I do not understand why you are using the variable countinString.
It is because you want to store the incrementation on variable i ?
Anyway why declare countString as a string ?
thanks , andre
let countString = ‘’;
let i = 0;
do {
countString = countString + i;
i++;
} while (i < 5);
I do not understand why cupsAdded stops at 3 when it is no longer less than cupsOfsugarNeeded when it at the same amount
let cupsOfSugarNeeded=2;
let cupsAdded=0;
do…while will run at least once whether or not the condition evaluates to true.
why you made the // cupsAdded=3 // you define it again!! and you made two time increment ?
Thanks for you great replay!
If we need to make a two time increment for this exercise, That’s mean I don’t understand the it!
I added one cup through (cupsAdded />/ cupsOfSugarNeeded) i make the condition false.
Onground I’m not understanding good and I start to see this topic in youtube.
Wish you a nice Day
Without the while is would not be a while loop, just a code block.
The only difference between while and do-while is when the condition is tested, before allowing the loop, which may not be allowed even one iteration, or after one iteration of the loop.
A while loop may run the code block at least zero times; a do-while may run it at least once.
The question sort of answers itself. Start with a value of 6, keep adding 1 until it reaches 9, at which point it will fail the condition test. A plain while loop would give the same result, and probably be a better choice of loop since the running variable is already defined.
@ jcinco, please post the code you are working on so we can see where the difficulty may be.
Hello mtf,
Please tell me if I am understanding this correctly.
Because the condition that has to be met, (in this case adding a cup of sugar: the “do statement”) happens before the code reads the “while statement,” which evaluates (as true or false), the condition will always occur one extra time over and above what the “while statement” would normally allow.
We would use DO…WHILE when we wish to have the code block execute at least once. This means we could define a variable within the code block, instead of before, and base the conditional on the state of that variable (or some other state) after running the code.