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

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

Does anyone know the answer to this question?

Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop.

It is Challenge Task 2 of 3

2 Answers

Hey Augusto,

First, you'll want to declare your String variable to store the user's eventual input. Then, you'll want to set-up your do-while loop. Inside the parameter of the do-while, set the loop to run as long as the user enters 'no'. It's good practice to convert the user's input to lower case or ignore it completely. This way, the loop will still run if the user types, "NO". Lastly, inside of your do-while loop, prompt the user and assign the result to your String variable.

Please note that I'm not using the same variable name or prompt as the challenge. This is just an example.

String userPrompt;
do {
    userPrompt = console.readLine("Do you understand...?");
} while(userPrompt.equalsIgnoreCase("no"));

Thanks, Jacob!

good answer.?