New course! Every coder should learn Generative AI!
Try a free lesson+ 7
If it's just for the fancy, I'd prefer to choose this style instead:
if(1)
{
{
{
{
printf("%d", 1);
}
}
}
} // ;-D
+ 10
Some recommend using them all the time.
+ 9
Hi Dynamic Squid.
I use curly brackets most of the time.
I need them especially when I have more than one instruction, within the condition. For clarity as well.
+ 6
Also, it helps to make your code more readable, organized, easier to debug.
+ 6
I would prefer to not use them, if I don't need them, to make the code shorter, but that means I'll have to add them manually and take them out each time I decide I need more than 1/only 1 argument after all, so it's probably more convenient to just always write them.
Or you switch to Python, where you don't need them at all. 😜
+ 5
For single line statement no need to use. like in your code you have single line statement in if condition so Doesn't matter to use of Curly brackets. But for multiline it's necessary like for loop.
+ 5
Dynamic Squid, to say that the reason for the existence of curly brackets is to be able to write multiple statements in a single line might be stretching it a bit.
+ 4
Just make sure that if the code you write is to be maintained by others, especially those coming from a Python background that if they add more statements under the if condition, they don't forget to add the curly braces. If not, their logic will be wrong.
+ 4
if you want to do fancy look of your code then you can use the curly brackets for the single statement also 😀
+ 4
AJ || ANANT || AC || ANANY || AY that's the hats off performance
And yes you already know I have use @.😀
+ 4
HonFu that's a very attractive piece of code 😁. Love the semicolon in the last comment as well 👍
+ 4
Arpan yes.
+ 3
One word. Scope.
+ 2
I use curly brackets whenever there is more than one line of code after the specified statement(for, while, etc.). If there is only one line, then I don't use them. It looks better to me.
+ 2
Must use when there are more than 1 statement
+ 2
This is called intend poeted :
+ 2
I will use curly brackets for one-line blocks if I feel the code is "important", or complicated. Curly brackets and maybe a line of whitespace between the brackets and the line of code lets the code breathe and makes it more prominent.
For less important code I will drop the brackets.
Imo there is a difference between
if (i == 0)
return options.default;
and
if (i == 0) {
return options.default;
}
When skimming and reading through code.
+ 2
For Single line of code no need of curly brackets if your code is multiline then you must use curly brackets otherwise it will generate an error
+ 2
For me I use curl braces when writing the main function which is obvious and the I use them when writing codes for control statements
+ 1
Raju Ram Sau I can make face of your also and print in that.😁😁