Need help with do-while loop
Hey guys.
trying to write a little script that will keep 2 numbers and will keep asking the user to enter a value until the value entered is one between the 2 numbers.
Just testing out some loops.
i guess the sample numbers can be anything - numbers(int min, int max){
just not sure how to do the do-while loop so it continues to ask for an input between them, lets say between 1 and 5.
any ideas.? i know its not a large script, maybe 5-9 lines, but just getting started.
Re: Need help with do-while loop
Code :
do{
System.out.print("Enter a number:> ");
myInt = myScanner.nextInt();
while(myInt > max || myInt < min);
Something like that you mean?
Re: Need help with do-while loop
Code :
do{
System.out.print("Enter a number ");
number = Keyboard.readInt();
}while(number> 4 || number < 10);
this will keep looping until the user enters a number greater than 4 and less than 10 if you want to include 4 and 10 just throw in an = sign after the less than and greater to signs.
Hope this helps.