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 Basics Perfecting the Prototype Censoring Words - Looping Until the Value Passes

If you tell it in while (isInvalidWord); if you told it inside the brackets

why do you have to tell it those words are bad twice? Inside the bracket and next to the while keyword.

The condition inside the while loop is used to display the message "invalid noun" only. The while condition is used to let the user enter a new noun.

At first, I thought the same. After all, if the while-statement says that the word is invalid, why check it again in the if-statement? However, the check in the if-statement is necessary, yet ONLY for the first run. (So during the 'do').

If you would not check in the if-statement, running the code would always state that 'That language is not allowed.' and that you have to try again, even when you entered something correct. If you would not check this in the while-statement, you get back at the previous situation, where you will have to System.exit(0) your code, or allow the bad language anyway.

So, even though this results in a repeating of the invalidWord-check (Γ‘fter a bad entry!), trying to get this out will result in repeating something even bigger. (Both the lines for entering a noun and the setting of isInvalidWord.)