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 trialnimrod bar-on
Courses Plus Student 1,085 PointsNot sure I got it right...
Hi,
In the video Dave says that the loop run as long as the while condition is true.
In the example correctGuess start with false;
The condition on the other hand is: run through the loop as long as correctGuess = true (! correctGuess)
That means that the loop run when the condition is false and exit when correctGuess become true and the condition become true too - the opposite of what Dave said.
If I understood it right the condition should be: as long as correctGuess = false (without the !, which mean that the condition is right) try again.
When you guess right, the correctGuess become true, the condition become false and the loop stop.
Am I wrong?
1 Answer
Jennifer Nordell
Treehouse TeacherThe condition for the while loop is this:
while ( ! correctGuess )
We start correctGuess as false. We only set correctGuess to true whenever the user guesses correctly. So what this loop is saying is run as long as correctGuess is not true. Hope this clarifies things!
I think what you're misunderstanding here is the "condition becomes false" part. The condition is the same thing as asking is correctGuess false? Yes. Then the condition is true. Is the correctGuess true? Yes. Then the condition is false.
edited for further explanation
From your post: That means that the loop run when the condition is false and exit when correctGuess become true and the condition become true too - the opposite of what Dave said.
No, value of the variable is false and this makes the condition true. Because we're checking to see if it's false. If it is false then the condition is true.