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

    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 offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    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

    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
    Rep Power

Similar Threads

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