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 trialRoger Hwang
3,851 Pointsdo 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
231,269 PointsThe 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
3,851 PointsRoger Hwang
3,851 PointsAh 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.