Curly brackets | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

14th Mar 2021, 3:27 PM
Andy
Andy - avatar
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
14th Mar 2021, 3:49 PM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 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
14th Mar 2021, 4:02 PM
A͢J
A͢J - avatar