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 8380753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:32:14+00:00 2026-06-09T16:32:14+00:00

After doing some reseach on how to break through a secondary loop while (true)

  • 0

After doing some reseach on how to break through a secondary loop

while (true) { // Main Loop
   for (int I = 0; I < 15; I++) { // Secondary loop
       // Do Something
       break; // Break main loop?
   }
}

most people recommended to call the ‘goto’ function

Looking as the following example:

while (true) { // Main Loop
   for (int I = 0; I < 15; I++) { // Secondary Loop
       // Do Something
       goto ContinueOn; // Breaks the main loop
   }
}
ContinueOn:

However; I have often heard that the ‘goto’ statement is bad practice. The picture below is perfectly illustrating my point:
Series found

So

  • How bad is the goto statement really, and why?
  • Is there a more effective way to break the main loop than using the ‘goto’ statement?
  • 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-09T16:32:16+00:00Added an answer on June 9, 2026 at 4:32 pm

    EDIT:

    How bad is the goto statement really, and why?

    It depends on the exact situation. I can’t remember any time where I found it made the code more readable than refactoring. It also depends on your personal view of readability – some people dislike it more than others, as is clear from the other answers. (As a point of interest, it’s widely used in generated code – all of the async/await code in C# 5 is based on effectively a lot of gotos).

    The problem is that situations where goto tends to be used tend to be the kind of situations where refactoring aids things anyway – whereas goto sticks with a solution which becomes harder to follow as the code gets more complicated.

    Is there a more effective way to break the main loop than using the ‘goto’ statement?

    Absolutely. Extract your method out into a separate function:

    while (ProcessValues(...))
    {
        // Body left deliberately empty
    }
    
    ...
    
    private bool ProcessValues()
    {
       for (int i = 0; i < 15; i++)
       {
           // Do something
           return false;
       }
       return true;
    }
    

    I generally prefer doing this over introducing an extra local variable to keep track of "have I finished" – although that will work too, of course.

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

Sidebar

Related Questions

DISCLAIMER: relatively new to Flex/AS3, I might be missing something obvious. After doing some
After doing some research, some people say I can add the following VM Argument
After doing some research on the subject, I've been experimenting a lot with patterns
I am building my own torrent site and after doing some research I have
After doing some Core animations using: [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [self setAffineTransform:CGAffineTransformIdentity]; [UIView
After doing some experimentation with move semantics with an array type I created, I
Update: I updated this after doing some digging and realizing that this might be
I'm getting a getaddress error and after doing some sleuthing, it looks like it
I have an activity with some views, after doing some stuff I want to
I got this message when doing some javascript programming, and after some google searches,

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.