Click here to Skip to main content
15,860,972 members
Articles
Reference
(untagged)

Braces and brackets

Rate me:
Please Sign up or sign in to vote.
4.40/5 (8 votes)
3 Nov 2000CPOL 1.6M   11   13
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)


Written By
Founder CodeProject
Canada Canada
Chris Maunder is the co-founder of CodeProject and ContentLab.com, and has been a prominent figure in the software development community for nearly 30 years. Hailing from Australia, Chris has a background in Mathematics, Astrophysics, Environmental Engineering and Defence Research. His programming endeavours span everything from FORTRAN on Super Computers, C++/MFC on Windows, through to to high-load .NET web applications and Python AI applications on everything from macOS to a Raspberry Pi. Chris is a full-stack developer who is as comfortable with SQL as he is with CSS.

In the late 1990s, he and his business partner David Cunningham recognized the need for a platform that would facilitate knowledge-sharing among developers, leading to the establishment of CodeProject.com in 1999. Chris's expertise in programming and his passion for fostering a collaborative environment have played a pivotal role in the success of CodeProject.com. Over the years, the website has grown into a vibrant community where programmers worldwide can connect, exchange ideas, and find solutions to coding challenges. Chris is a prolific contributor to the developer community through his articles and tutorials, and his latest passion project, CodeProject.AI.

In addition to his work with CodeProject.com, Chris co-founded ContentLab and DeveloperMedia, two projects focussed on helping companies make their Software Projects a success. Chris's roles included Product Development, Content Creation, Client Satisfaction and Systems Automation.

Comments and Discussions

 
GeneralOld post Pin
mbaocha6-May-09 12:32
mbaocha6-May-09 12:32 
GeneralRe: Old post Pin
vbCoder2120-Jan-10 12:25
vbCoder2120-Jan-10 12:25 
GeneralRe: Old post Pin
StianSandberg2-May-13 1:23
StianSandberg2-May-13 1:23 
GeneralBalancing between disk usage & readability Pin
1-Sep-01 3:10
suss1-Sep-01 3:10 
GeneralRe: Balancing between disk usage & readability Pin
NebuGranny29-Mar-04 9:51
NebuGranny29-Mar-04 9:51 
GeneralRe: Balancing between disk usage & readability Pin
Derek Bartram22-Mar-08 11:26
Derek Bartram22-Mar-08 11:26 
QuestionHow about spaces Pin
AlexMarbus27-Feb-01 7:27
AlexMarbus27-Feb-01 7:27 
AnswerRe: How about spaces Pin
Jason Douglas2-Mar-01 3:38
professionalJason Douglas2-Mar-01 3:38 
AnswerRe: How about spaces Pin
2-Mar-01 6:05
suss2-Mar-01 6:05 
GeneralRe: How about spaces Pin
James R. Twine4-Mar-01 7:51
James R. Twine4-Mar-01 7:51 
AnswerRe: How about spaces Pin
Simon Hughes2-Apr-01 0:24
Simon Hughes2-Apr-01 0:24 
AnswerRe: How about spaces Pin
1-May-01 4:06
suss1-May-01 4:06 
AnswerRe: How about spaces Pin
[James Pullicino]4-May-01 4:45
[James Pullicino]4-May-01 4:45 

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

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