I am having trouble with my do while loop not finding my variable to test if the condition is true or not. Here is my code:
import java.util.Scanner;
public clas
You are out of scope because you are using a do{} while()
loop. When java reaches the do
statement, it skips down to your while
statement to make sure it returns true. It doesn't even see the code in the middle until after that.
It's much easier to see the correct scope of a variable if you use a while(condition){body}
statement since the variable is at the top, where we naturally expect the code that is executed first to be.
So I would use a while loop as explained above, and you will have to declare the play
variable before that line. Hope that works :)