Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2014
    Posts
    1
    Rep Power
    0

    Default Can you have two options to stop a do...while loop?

    In the code that I am currently trying to do, I want to make it so that the program loops until the randomly generated number is 1, to a maximum of 4 loops. How can I go about doing this?
    I have figured out how to make it stop at a randomly generated 1, but I can't quite figure out how to make it stop at four loops if it doesn't reach the 1 before the maximum number of loops.
    I may be just overthinking this, but I would really appreciate some advice.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Can you have two options to stop a do...while loop?

    The loop iterates based on a condition. Sounds like you have a condition in the
    form of a && b, where a and b are appropriate expressions.

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

  3. #3
    Java Guy is offline Member
    Join Date
    Oct 2014
    Location
    Null
    Posts
    3
    Rep Power
    0

    Default Re: Can you have two options to stop a do...while loop?

    Here is a quick solution to your question. I have to run to the house real quick. When I get home I will elaborate more on my logic and will comment the code for you. Hope this quick solution helps.

    *** Code removed
    Last edited by Norm; 10-11-2014 at 03:54 AM. Reason: Please don't do OPs work for him

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    10

    Default Re: Can you have two options to stop a do...while loop?

    Hi and welcome to the forums.

    Since you know the number of repetitions perhaps a for loop would be more appropriate.
    If only there was a way to cause a loop to 'break'...

    Regards.

Similar Threads

  1. How to get a for loop to stop with break/return
    By shaeway in forum New To Java
    Replies: 13
    Last Post: 07-23-2013, 08:46 PM
  2. Trying to stop a 'for' loop
    By monster10888 in forum New To Java
    Replies: 3
    Last Post: 10-11-2012, 09:41 PM
  3. break or stop for loop
    By mitra in forum New To Java
    Replies: 7
    Last Post: 09-13-2011, 12:39 AM
  4. how to stop for loop
    By rjagan in forum New To Java
    Replies: 3
    Last Post: 04-01-2011, 05:15 PM
  5. help!, while loop wont stop!
    By crank6015 in forum New To Java
    Replies: 4
    Last Post: 03-24-2011, 03:27 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
  •