Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need help with do-while loop

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Need help with do-while loop

    do{
       System.out.print("Enter a number:> ");
       myInt = myScanner.nextInt();
    while(myInt > max || myInt < min);

    Something like that you mean?

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Need help with do-while loop

    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.

Similar Threads

  1. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 05:27 PM