Trying to run the while loop for a password check. I do keep getting an error that the variable haslo cannot be found. Tried declaring it outside the loop - then it says, it's already declared. I know it can be done with infinite loop and the break command. Just curious whether it's possible this way.
String password = "pw123";
while (!haslo.equals(password)){
System.out.println("Enter pw:");
String haslo = reader.nextLine();
if (haslo.equals(password))
System.out.println("Right!");
else
System.out.println("Wrong!");
}
haslo = reader.nextLine();