Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Review while loops, do...while loops, and Loop Conditions

Roger Hwang
Roger Hwang
3,851 Points

do while loop question

do { console.log('Hello'); } while (false) console.log('Goodbye');

How does this statement print out 'Goodbye'? Where in the code does it value to false?

1 Answer

Steven Parker
Steven Parker
231,275 Points

The loop starts with "do" and ends with "while". It's a "do...while" loop, not an ordinary "while" loop.

So the part the prints out "Goodbye" comes after and outside the loop, and will always be done.

Roger Hwang
Roger Hwang
3,851 Points

Ah I get it! "console.log('Goodbye');" is not in curly braces in which I was picturing that's how it was set up to be which would then be dependent on the while loop. Further, do while loops syntax should just ends in "while()". Definitely a tricky one considering do while's aren't used as much.