FAQ: Loops - Do...While Statements


This community-built FAQ covers the “Do…While Statements” exercise from the lesson “Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Do…While Statements

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 (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 (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!



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;
} 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;

} while(cupsAdded < cupsOfSugarNeeded){



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 ?



do {
    // something
} while (condition);

It ends there. There is no such thing as,

do {
    // something
} while (condition) {
    // do something;

It’s either,

do {
    // some action
} while (condition);


while (condition) {
    // some action


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


let cupsOfSugarNeeded=9;

let cupsAdded=6;

} while(cupsAdded < cupsOfSugarNeeded);


why cups added output is 9 ? isnt suppose to be 3 ?


Each iteration of the loop increases (increments by 1) the value up to 9, which is the termination condition.