It’s probably something obvious, but when I’m trying to force the user to keep entering a value until he enters a valid value, I get an error that the variable cannot be resolved.
Then if I declare it beforehand I get an error saying duplicate value.
do {
float x = Float.parseFloat(javax.swing.JOptionPane.showInputDialog("Enter 1");
} while (x != 1);
Isn’t the compiler supposed to execute the do statement first, before worrying about the while?
declare
xbefore the loop, make its scope more broder like below :