Welcome to the Treehouse Community
Looking to learn something new?
why does he use a while in this example and not a if and else
Steven Parker216,148 Points
You didn't provide a link to "this example", so I don't know what you are referring to. But "if" just makes a section of code conditional, based on a comparison or boolean variable.
On the other hand, "while" establishes a loop to cause a section of code to be done more than once; repeating until a condition is not met or some variable becomes "falsey".
They both take a conditional expression, but what they do with it is different.