Question about correct format of code

closed account (3qX21hU5)
So lately on these forums I have seen alot of people using formating like this

1
2
3
4

for (int index = 0; index != n; ++index) { // <- the opening brace
    // whatever stuff 
}


Now for me the opening brace looks wierd right there and if there is loops inside other loops it starts to get really onfusing for me to read. Now I know everyone has there own style for programming and there is always different ways of formating. Im just wondering if the above code is the standard way of doing it and if I should start getting used to doing it that way.

Heres how I do it usually

1
2
3
4
for (int index = 0; index != n; ++index)
{   // <--- opening brace here
   
}


Thanks in advance for the help.
You are describing K&R vs Allman style braces. They are all standard.
#1 rule: be consistent.
Last edited on
I have seen quite a few arguments of people listing the pros/cons of each style and insulting anyone who uses the other way. You can't really call 1 'standard' over the other.

I prefer the 2nd way as I find it much easier to see what is going on, but as long as the formatting is easy to understand and consistent I really wouldn't worry about it.
I was taught the first way when I was in school, but I prefer the second way as it's easier to match up the brackets. Choose 1 and be consistent.
closed account (3qX21hU5)
Thanks for the replies guys. So just basically pick a style that you feel more comfortable with and be consistent with it.
Topic archived. No new replies allowed.