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 trialDenise Falcone
1,053 PointsPlease explain why this false condition causes an infinite loop
Hi- I don't understand why this code causes an infinite loop. Can someone walk me through the logic? (I'm having trouble with strings logic compared to math logic.) I thought false means the loop stops after the code runs one time? Thank you!
do { console.log('Hello'); }
while (false);
console.log('Goodbye');
1 Answer
Robert Manolis
Treehouse Guest TeacherHi Denise Falcone , I just copied your code and ran it myself and it didn't result in an infinite loop. If I changed the condition from false to true, then I got an infinite loop. But with false in there, it just logged Hello once, and then Goodbye.
Denise Falcone
1,053 PointsDenise Falcone
1,053 PointsThank you! That makes sense-- I came across this code in a quiz challenge and misunderstood why my answer was incorrect (I chose Hello would log once and neglected the Goodbye line.)