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 Looping until the value passes

Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don'

I just need some help with this, iv'e watched the video and also googled some stuff about do while loops and i still can't find a answer well if i did i just don't understand, please let me just get some help on this so i'm not stuck on it for weeks.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response = console.readLine("Do you understand do while loops?");
do { 
  noun = console.readLine("no");

  }
} while(inInvalidWord);

1 Answer

Lukas Baumgartner
Lukas Baumgartner
14,817 Points

Try to think it through what you are doing:

In your "response" variable, you are saving the userinput. Currently, you prompt the user just once.

Then, in your loop, you have "noun" that is currently nothing, and eventually not even needed. You end your loop again on nothing, because "inInvalidWord" is never initialized.

Here is some pseudocode:

Make a String variable named prompt;
do{
   get the input from the user and save it in your promptvariable;
}while(loop as long as the user gives the right input );

If there are any further questions, feel free to ask.