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

Justin Townsend
Justin Townsend
4,720 Points

Java noob

I have watched the previous video 3 times and i still don't understand what I am suppose to do

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 while loops?");
Mihailo Jakovljevic
Mihailo Jakovljevic
9,259 Points

Hi i'm not sure what you do not understand so i am going to explain to you everything step by step. Step 1:

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

This is pretty straightforward and i can see that you understand it. Step 2:

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

What you are doing here is creating a do while loop. The main difference between do while and while loop is that do while loop is guaranteed to loop at least once. So you will input you answer in console if its "No" it will loop again and if it anything else you will exit the loop. Step 3:

String response;
do{
    response = console.readLine("Do you understand do while loops?");
}while(response.equals("No"));
console.printf("Because you said %s, you passed the test", response);

Now you just print out the result. Hope this helps :D

1 Answer

Justin Townsend
Justin Townsend
4,720 Points

Thanks brother the part I didn't grasp was the do while loops, loops are a bit confusing for me

Mihailo Jakovljevic
Mihailo Jakovljevic
9,259 Points

No problem they were tough for me as well when i started java, but the most important thing is to keep grinding.