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 Exiting Loops

The while(true) {...} function

what does the boolean 'true' represents in while(true) {....}.

While(what is true?){...}

Thanks

3 Answers

While true is true. While just looks for a true/false value. Saying while(true) just skips the evaluation and will always loop, until you use a break. It's just a way to generate an infinite loop.

It's clearer.

Antonija Kasum
Antonija Kasum
4,918 Points

Can anyone offer other explanation, still not sure I get it :/.

All a while statement does is look to see if a value is true or false. So if you put while(true), you can assume true is always going to equal true, and your loop won't stop unless you stop it.

Antonija Kasum
Antonija Kasum
4,918 Points

I understand it now but John Breslin you explanation makes most sense