Can i use if else without braces?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can i use if else without braces??

15th Aug 2016, 7:19 AM
Anamul Arshad
Anamul Arshad - avatar
4 Answers
+ 10
yes you can but when there is only one state ment after it eg. if(condition) cout << "Hello World" << endl; else cout << " hi" << endl; // this is right when there is only one statement but if (condition) cout << "hello" << endl; cout << " world" << endl; // this is wrong as there are two statement it should be under braces {}
15th Aug 2016, 8:23 AM
raj
raj - avatar
+ 3
Thanks
16th Aug 2016, 5:46 AM
Anamul Arshad
Anamul Arshad - avatar
+ 1
yes if else statement can be implemented without using braces but only when there is single statement
13th Jan 2017, 7:42 PM
Parth
Parth - avatar
+ 1
U can use but there may be more than 1 condition.... then only u can use without braces
17th Feb 2017, 10:40 AM
Raja Chouhan
Raja Chouhan - avatar