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

Shiva Lowy
seal-mask
.a{fill-rule:evenodd;}techdegree
Shiva Lowy
Full Stack JavaScript Techdegree Student 3,240 Points

I am very confused and lost. I am not sure what I am doing wrong.

I am trying to do the loop code and it is not working for me. I tried to go back in the video and check but the code still is not working. Please help!! Thanks!!

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 do while loops?");
String response;
boolean response; 
do {
  response = console.readLine("No."); 

4 Answers

First off String response is already initialized at the top, so creating another variable with the same name will give you an error. Second, for a do while loop it needs to be like so

do {
  //code here will run at least once
} while (boolean condition)

the do loop will always run at least once and will keep running as long as the condition in the while is true.

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

do{ response = console.readLine("Do you understand do while loop?"); } while(response.equalsIgnoreCase("no"));

please remove the extra "); in the first line