Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Asynchronous Programming with JavaScript What is Asynchronous Programming? Examples of Synchronous and Asynchronous Code

While loop

First of all, I know how While loop behaves. It means when the condition statement is true, it will keep running. If not true, it will stop.

But in this tutorial, i cant understand the logic behind the while loop. Is that means if the time is below 8000, it should printout much more 'finished' string. Then after 8000miliseonds it appear one result.

I just dont know the logic behind it.

Hope someone can help me out, thank you so much!

1 Answer

Steven Parker
Steven Parker
215,984 Points

If you look closely, you can see that the "while" statement has a semicolon (";") at the end of it. This means that loop has an empty body, so there is no code that is executed when the condition is true.

So the loop does nothing but keep testing the condition. It essentially just "waits" for the condition to be false, which will occur after 8 seconds (8000 milliseconds).

The log statement comes after the loop and is only done once after the loop finishes.

Oh......I totally missed that. Thank you so much!!