Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:22:37+00:00 2026-06-07T02:22:37+00:00

How can my loop branch back to looking for input if there is no

  • 0

How can my loop branch back to looking for input if there is no work to do?

I’m making a script that essentially asks for 3 or 4 raw_input lines, and then does some work based on those, and loops infinitely. However, the raw_input lines are choices (I’m looking for them to type one of a few statements). Instead of a mess of booleans and while loops to make sure it’s an acceptable statement, I thought it might be easier and cleaner to simply do something like this:

if theInput != 'Acceptable Statement' and theInput != 'Another acceptable statement':
    restartLoop()
if theSecondInput != 'Acceptable Statement' and theInput != 'Another acceptable statement':
    restartLoop()

And so on, for every input I need. It would abort the current cycle and restart with another, as if it had finished. Since nothing actually happens until all the data is collected and approved, this shouldn’t cause any problems. I realize this is an alternative:

if theInput == 'Acceptable Statement' or theInput == 'Another acceptable statement':
    if theSecondInput == 'Acceptable Statement' or theInput == 'Another acceptable statement':
        doThings()
    else:
        doNothing()
else:
    doNothing()

However, I’d like it to end the loop after the input the user gets wrong, instead of asking them 5 questions and eventually telling them they got #2 wrong.

EDIT: Just to be a bit clearer, I still want to infinitely loop (nothing but leaving the shell will leave the loop), I just want to restart the loop without completing. IE, when making many of a product, you are in a loop with a few steps. But, if you perform a step incorrectly, you throw out the faulty product and start over without finishing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:22:39+00:00Added an answer on June 7, 2026 at 2:22 am

    Nested ifs will work just fine, and you can make them neater, too:

    if theInput == 'Acceptable Statement' or theInput == 'Another acceptable statement':
        if theSecondInput == 'Acceptable Statement' or theInput == 'Another acceptable statement':
            doThings()
            break
    

    But continue will do what you need. I just find the above nicer-looking 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I loop through all members in a JavaScript object, including values that
I have a loop that can look like this: For Each article In artAll
How I can loop some action in Cocoa? For example I want that random
Is there a way I can loop through the set of classes in a
Is there a pythonic way (I know I can loop using range(len(..)) and get
I can loop through all of the rows in a php script and do
Is there any way I can loop through all the dijit fields in a
I am trying to define an array of file paths that I can loop
I know I can loop through a list of strings like this: list<string>::iterator Iterator;
How can I loop through the array below and an element per array, with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.