If Else statements when and where to use these respective braces. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If Else statements when and where to use these respective braces.

What is the difference between: 1) if ( condition) { Statement } 2) if (condition) Statement

16th Dec 2019, 2:41 PM
Dipanjan Basu
Dipanjan Basu - avatar
2 Answers
+ 3
When there is only one statement, braces can be omitted. (Option 2) but not necessary. When there are more than one statements, you have to use proper braces. (option 1 must follow here). ex: 1) if(a>b) { max=a; //more than 1 statements min=b; .. } 2) if(a>b) max=a; //single statement.
16th Dec 2019, 2:52 PM
Jayakrishna 🇮🇳
0
Clean code says you shouldn't use 2nd statement as it's making code less readable ^^
16th Dec 2019, 3:52 PM
Jakub Stasiak
Jakub Stasiak - avatar