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 trialHan Wu
927 PointsWhat does the "while" command do?
Can someone explain it's entire function please?
1 Answer
Daniel Hartin
18,106 PointsHi Han
While is used to create a loop based on the outcome of a calculation. For example in english you could say while the car is dirty keep washing, the same is true in programming, while a condition is true the block of code will continue to literate over and over again until the condition is met and the code can break out of the loop.
There are numerous loop types in java and some suit situations better than others, while loops can be dangerous as if the condition is never met you can end in an unintentional infinite loop but are great if you handle the condition correctly
Hope this helps Daniel
Han Wu
927 PointsHan Wu
927 PointsOhhh I get it now. Thank you!