0

How do you create a while loop that goes back to a Scanner request for user input?

I'm trying to make a loop that returns an entry in an array when the user inputs a number within a certain ragne. If I assign a variable to the Scanner before the loop, I can't go back to it if the user input isn't inside the range, If I put it inside the loop, the variable isn't defined yet when used in the loop parameters. Any ideas?

8th Apr 2019, 7:59 PM
Jason
Jason - avatar
2 Answers
+ 2
Do you mean something like this? int i = 0; while(i != outside range){ i = yourScanner.nextInt(); //do something with i } But it is not possible in Sololearn. You have to use your IDE on your PC.
8th Apr 2019, 9:52 PM
Denise Roßberg
Denise Roßberg - avatar
0
That is exactly what I needed to know. I was assigning the variable to the Scanner before the loop. I didn't even think of just giving it a different initial value. Thank you.
8th Apr 2019, 10:55 PM
Jason
Jason - avatar