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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:51:35+00:00 2026-05-31T08:51:35+00:00

I am writing some C code and in my code I have two nested

  • 0

I am writing some C code and in my code I have two nested loops. On a particular condition I want to break out of the inner loop and continue the outer loop. I tried to achieve this using a label at the end on the outer loop’s code and, on the condition, goto that label. However gcc gives an error that I cannot have a label at the end of a compound statement. Why not?

Note 1: This is not a switch statement and that question has been answered elsewhere.

Note 2: This is not a question about style and whether I should or should not be using goto statements or conditional variables instead.

EDIT: People have asked for an example and I can give a slightly facile example of checking if an array is a subarray of another array

    int superArray[SUPER_SIZE] = {...}, subArray[SUB_SIZE] = {...};
    int superIndex, subIndex;

    for (superIndex=0; superIndex<SUPER_SIZE-SUB_SIZE; superIndex+=1)
    {
      for (subIndex=0; subIndex<SUB_SIZE; subIndex+=1)
        if (superArray[superIndex+subIndex] != subArray[subIndex])
          goto break_then_continue;

      // code that executes if subArray is a sub array

      break_then_continue:
    }
  • 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-05-31T08:51:37+00:00Added an answer on May 31, 2026 at 8:51 am

    In the standard it’s explicitly said that labels belong to a statement, therefore a simple semicolon (;) after your label can circumvent the problem you are running in to, since that counts as a statement.

    There is even an example of the use of an “empty“1 statement in 6.8.3/6.

    EXAMPLE 3 A null statement may also be used to carry a label just
    before the closing } of a compound statement

    while (loop1) {
      /* ... */
    
      while (loop2) {
        /* ... */
    
        if (want_out)
          goto end_loop1;
    
        /* ... */
      }
    
      /* ... */
    
      end_loop1: ;
    }
    

    1 In the standard this is referred to as a null statement.


    6.8.1 Labeled statements

    Syntax
      1 labeled-statement:
          identifier : statement
          case constant-expression : statement
          default : statement
    

    Notice that statement isn’t optional in the above quotation.


    • open-std.org: n1124.pdf
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across an annoying problem while writing some PHP4 code. I renamed
I have some code like this in a winforms app I was writing to
I am writing unit tests for some of my code and have run into
I have been messing around with writing some stored procedures in .NET code with
I'm writing a web page in ASP.NET. I have some JavaScript code, and I
Does anyone have some good hints for writing test code for database-backend development where
I'm writing some code for a class constructor which loops through all the properties
I'm writing some code that uses a Tree (a regular tree that can have
Quick question. I was writing out some code and was curious if there is
I have just written some code, which as i was writing i thought, this

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.