Results 1 to 3 of 3
  1. #1
    MichiKen is offline Member
    Join Date
    Sep 2013
    Posts
    19
    Rep Power
    0

    Default Using a "Yes/No" prompt in a For loop

    I'm trying to write code where the user would select a case that contains different amounts of money. They get three attempts. However, if they like the amount they got before the third attempt they can stop at that point and the program terminates.

    I've created a for loop:

    Java Code:
    for (numofGuesses=0;numofGuesses < 3; numofGuesses++) {
    
    
    break; (if user says "no" to continuing, break out of the loop)
    }
    I'm having trouble figuring out the syntax for creating a prompt that asks them if they want to continue and they answer with "y" or "n". If they answer "y" it stays in the loop, if "n", it breaks out of the loop and the program terminates.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,782
    Rep Power
    5

    Default Re: Using a "Yes/No" prompt in a For loop

    You need to know the following:


    1. How to use for loops.
    2. How to accept user input.
    3. How to compare strings.
    4. How to exit a loop


    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,098
    Rep Power
    6

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. Replies: 1
    Last Post: 02-01-2012, 08:37 PM
  4. An "if" statement inside a "for" loop?
    By soccermiles in forum New To Java
    Replies: 18
    Last Post: 04-20-2010, 03:44 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •