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

  • SEARCH
  • Home
  • 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 8638333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:42:11+00:00 2026-06-12T10:42:11+00:00

I have a lot of if statements in while loop, program has to print

  • 0

I have a lot of if statements in while loop, program has to print error messages according to conditions, but if there are more than one error it has to be only one of them.

  • 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-12T10:42:13+00:00Added an answer on June 12, 2026 at 10:42 am

    Your question isn’t very detailed so it’s a little hard to tell what exactly do you want.

    If you want the while loop to go to the next iteration after any error has fired, you should use the continue statement:

    while( something )
    {
        if( condition )
        {
            //do stuff
            continue;
        }
        else if( condition 2 )
        {
            //do other stuff
            continue;
        }
        <...>
    }
    

    If nothing else than these ifs is inside the loop, and the conditions are integer values, you should consider using switch instead:

    while( condition )
    {
        switch( errorCode )
        {
            case 1:
            //do stuff;
            break;
            case 2:
            //do other stuff;
            break;
            <...>
        }
    }
    

    If you want to completely restart the cycle… well this is a little harder. Since you have a while loop, you can just set the condition to it’s starting value. For example, if you have a loop like this:

    int i = 0;
    while( i < something )
    {
        //do your stuff
        i++;
    }
    

    then you can “reset” it like this:

    int i = 0;
    while( i < something )
    {
        //do your stuff
        if( something that tells you to restart the loop )
        {
            i = 0;//setting the conditional variable to the starting value
            continue;//and going to the next iteration to "restart" the loop
        }
    }
    

    However, you should be really careful with this, it’s easy to get an infinite loop accidentally.

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

Sidebar

Related Questions

I have a lot of logging statements in my code. While these make for
I have a shell script with a lot of echo statements. I want to
I have a PHP file that contains a lot of if and else statements
Is there any better way of handling nested else if statements that have different
I have a do...while loop and a try...catch block that wraps around database centric
I have a method that has many many statements like this: employee.LastName = file.EMPLOYEE.NAME.SUBNAME.FAMILYNAME.NAMEPART1.Value;
This question has been asked a lot here, but i still can't fix my
I have lot of products with custom options, now I have requirement to update
I have lot of code in my Tornado app which looks like this: @tornado.web.asynchronous
We have lot of object with this kind of design : Interface and several

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.