+ 1
Curly brackets
So I was trying to figure some stuff out about these two different ways to write curly brackets. Here's an example: 1) if (condition) { } 2) if (condition) { } So in the first example you write the open brace after the condition and in the second example you write the open brace under the condition, so my questions were: 1.Is there a name for these two ways of writing the curly brackets? 2.Which way is more used in professional programming?
2 Answers
+ 3
1) I never heard anything about names of these ways, everyone just calls them "opening on the same/next line".
2) It is a personal preference. You should use the one you like. Personally I always open the bracket on the same line
+ 3
No there is no name of these ways. You can write in any ways. I mostly prefer this
if(condition) {
}
because we can save 1 extra line. So if there are many conditions then we can save more extra line..
If there is a single statement then I don't like to use curly braces. I just write
if (condition) //statement