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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:47:35+00:00 2026-05-17T18:47:35+00:00

Bad style notwithstanding, is it legal C to have a for loop with braces

  • 0

Bad style notwithstanding, is it legal C to have a for loop with braces inside the parens? Like this:

char *a = "a ";
char *b = "b ";

for ( { int aComesFirst = 1;
        char *first = a;
        char *second = b;
      };
      aComesFirst >= 0;
      { aComesFirst--;
        swap(first, second);
      } )
{
  printf("%s%s\n", first, second);
}

If something along those lines is possible, am I supposed to put a semicolon after the first close braces, or would that add an empty statement?

I do realize that it is stylistically better to move the char* declarations outside the for loop and the swap to the end of the inside of the loop. But style is not the point of this question, I just want to know if putting braces inside the parens is possible.

  • 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-17T18:47:36+00:00Added an answer on May 17, 2026 at 6:47 pm

    I’ve answered this before… this can easily be made legal in C or C++ by adding a local struct type. It’s generally poor style, though.

    char *a = "a ";
    char *b = "b ";
    
    for ( struct loopy {
            int aComesFirst;
            char *first;
            char *second;
          } l = { 1, a, b }; /* define, initialize structure object */
    
          l.aComesFirst >= 0; /* loop condition */
    
          l.aComesFirst--, /* loop advance */
          swap(l.first, l.second)
        )
    {
      printf("%s%s\n", l.first, l.second);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In short I have code like this. I know its bad style but have
i have something like this class A { virtual void doBla(A *a) = 0;
This is a cross language question on coding style. I have to work with
I'm going to do two something that is considered bad style, but I have
I get a Error: Warning 25: bad style, all clauses in this pattern-matching are
Is it considered as bad style to have a mixture of exact width types
I'm just wondering - is it bad programming style to create functions (decomposition) for
This bad boy just does not want to change size to fill the dock
Is it bad practice to have a custom cursor on a website? Not just
I feel bad because it is very likely this has already been answered and

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.