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

Enyang Mercy
PLUS
Enyang Mercy
Courses Plus Student 2,339 Points

Do while loop Prompt user

Question: do u understand do while loops? Result in string variable named response

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.



 do

2 Answers

michaelcodes
michaelcodes
5,604 Points

Hi there. First we want to declare the variable "response" to hold the users input to the question. to get there input we use console.readLine. Since we want to keep prompting the user this question repeatedly until a condition is true we wrap that in the do tags.

String response;
do{
response = console.readLine("Do you understand do while loops?");
} 

Now to finish it off we have to state the condition by which to keep repeating. this is while part:

while (response == "No");

The entire do-while loop:

String response;
do{
response = console.readLine("Do you understand do while loops?");
} while (response == "No");

Hope this helps. Take care!