Click here to Skip to main content
Licence CPOL
First Posted 14 Nov 1999
Views 52,567
Bookmarked 9 times

Braces and brackets

By | 3 Nov 2000 | Article
Options for placing braces

Options for Parentheses

Option 1: Spaces between inside and outside the parentheses. 

if ( something )
...

Option 2: Spaces outside parentheses, no space inside.

if (something)
...

Option 3: Spaces inside parentheses, no space outside.

if( something )
...

Option 4: No white space.

if(something)
...

Options for braces

Option 1: Braces starting on control line.

if (something) {
  // statements
}

Option 2: Braces starting on line under control line, non-indented.

if (something) 
{
    // statements
}

Option 3: Braces starting on line under control line, indented.

if (something) 
    {
    // statements
    }

Option 4: Braces starting on control line, closing brace indented.

if (something) {
    // statements
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Chris Maunder

Founder
The Code Project
Canada Canada

Member

Follow on Twitter Follow on Twitter
Google+
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralOld post Pinmembermbaocha12:32 6 May '09  
GeneralRe: Old post PinmemberHarsimran Singh (.NET)12:25 20 Jan '10  
GeneralBalancing between disk usage & readability PinmemberAnonymous3:10 1 Sep '01  
GeneralRe: Balancing between disk usage & readability PinmemberNebuGranny9:51 29 Mar '04  
GeneralRe: Balancing between disk usage & readability PinmemberDerek Bartram11:26 22 Mar '08  
QuestionHow about spaces PinmemberAlexMarbus7:27 27 Feb '01  
AnswerRe: How about spaces PinmemberJason Douglas3:38 2 Mar '01  
AnswerRe: How about spaces PinmemberAnonymous6:05 2 Mar '01  
GeneralRe: How about spaces PinmemberJames R. Twine7:51 4 Mar '01  
AnswerRe: How about spaces PinmemberSimon Hughes0:24 2 Apr '01  
AnswerRe: How about spaces PinmemberYoko4:06 1 May '01  
AnswerRe: How about spaces PinmemberJames Pullicino4:45 4 May '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120528.1 | Last Updated 4 Nov 2000
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid