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

Classified Classified
Classified Classified
767 Points

Where do I go from here?

I have to create a loop. I've forgotten completely everything up to this point. I've even checked back on the video, but that's obviously no help.

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

1 Answer

Simon Coates
Simon Coates
28,694 Points

the first result if you google "java while loops" is Oracle's official explanation. You can use this, a little knowledge of scopes and the oracle documentation of java.io.Console (the console object is an instance of this) to put together the complete solution. If you're only interested in the solution to a treehouse question, these are usually already posted in the forum with often detailed explanations of what is occurring (eg https://teamtreehouse.com/community/how-to-make-a-loop-in-java ).

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

/* //part 1:
String response = console.readLine("Do you understand do while loops?");
*/
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);
Simon Coates
Simon Coates
28,694 Points

oh, and you should know about the difference between == and equals.