Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

mason malone
415 Pointswhat do i do
edrsdfdfsdfsdfs
response = console.readLine("Do you understand do while loops?");
String response;
while(true) {
response = console.readLine("Do you understand do while loops?");
if (!response.equals("No")) {
break; } }
1 Answer

Steve Hunter
57,684 PointsHi Mason,
First, you've declared response
as being a String
and get user input to a question using console.readLine()
. That's the first stage of the challenge and it looks like this:
String response = console.readLine("Do you understand while loops?: ");
You've got beyond that bit and on to stage 2. Here, you need to create a do/while
loop. The loop will always execute once and will continue to loop while
the response
equals "No". You need to amend the above response
declaration to just create a variable but assign nothing to it. Then you create a do/while
loop. That looks like:
String response;
do {
// keep doing this
response = console.readLine("Do you understand while loops?: ");
} while(condition);
The condition
is a test of what the user has input. If they have entered "No", loop. Else don't ... So we need to test if response
is "No". To compare strings, use the .equals()
method. We can build this into the code:
String response;
do {
response = console.readLine("Do you understand while loops?: ");
} while(response.equals("No"));
That's stage 2 complete! Go figure out stage 3 and let me know how you get on.
I hope that helps,
Steve.