Do...While Statements Help

So recently, I just started programming. I’ve come across this obstacle that I can’t really avoid, and it really bothers me.
Do… While Statements, I just can’t understand them and I cannot find an answer, so I was thinking that someone from codecademy forums will help me. I cannot understand their role in the code and why are they even there.
Like "let cupsOfSugarNeeded = 5;
let cupsAdded = 0;

do {
console.log(cupsAdded + ’ cup was added’)
} while (cupsAdded < cupsOfSugarNeeded);
" What does the “while” even do?
it’s probably my lack of experience, and I’m sorry if my question is too dumb, but I can’t pass this.

1 Like

It keeps on doing the thing you asked until the condition is true.

So it runs this part:
console.log(cupsAdded + ’ cup was added’)

and then it checks if the while part (cupsAdded < cupsOfSugarNeeded) is true. If it’s not, it does it again. and again. and again. And so on until it is true.


Let me get this correctly, so you basically execute a code in the do{}, and the “while” statement checks a condition like
"let countString = ‘’;
let i = 0;

do {
countString = countString + i;
} while (i < 5);
" Also thanks for replying it really helps me a lot!

1 Like

Yes, that’s right. You’ve got it!