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

Java Java Objects Delivering the MVP Validating and Normalizing User Input

What's the point adding do while loop in promptForGuess?

I didn't quite understand what was the point of adding the do while loop in promptForGuess, because I left promptForGuess unchanged ( I left it as it was from the last lesson) and it still works perfectly. It feels as if Craig here is breaking the KISS rule, but I'm sure there is more to it.

1 Answer

Gabriel Precup
Gabriel Precup
4,565 Points

It helps for checking each time if the variable "isAcceptable" is false, so when it becomes true, it jumps over that loop. It changes to true the moment the guesser inputs a non-null value. If there is a null value, it will just jump over "isAcceptable=true", because the program identifies the exception when running "applyGuess(guess)"