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

what the condition i put in while loop?? why i got an error again and again ??

java basics do while loop programming assinment

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do{
 response = console.readLine("Do you understand do while loops?");
  if(response.equals("No")){
    System.exit(0);
  }
 }while( response != ("No"));
console.printf("No");
Richard Lambert
Richard Lambert
Courses Plus Student 7,180 Points

Hello mate,

I recently answered a similar question covering this task. There are a few issues with this code:

  1. At the moment, your code will prompt for input, and if that input happens to be a string value of "No", the Java virtual machine terminates and code execution stops, which isn't the expected outcome for this task.
  2. There is no need to check for the condition that causes execution of the do-while statement to end, from within its body; this is what the do-while statement's builtin conditional expression is for.
  3. The logic of your conditional expression is the inverse of what is required. At the moment this expression is saying while the user's response does not equal "No" continue looping when it should be while the user's response equals "No" continue looping.
  4. There's no need to place parenthesis around the "No" string in your do-while statement's conditional expression, nor is there any need to print a formatted string with the value "No" to the console.

Hope this helps