+ 3

Why dont we use cali-brackets {} in C++ when we using the if statemets

I have seen many programs & I have done some..if use {} it doesn't work

14th Mar 2018, 10:29 AM
Ronald Mbanjwa
Ronald Mbanjwa - avatar
3 Réponses
+ 6
We do! but some people prefer not to when there is only one instruction line following the if statement: if(...) // one line instruction if(...) { // instruction // more instruction } If there is more than one line of instruction following if statement wrap them in curly braces, one line? not necessary, but if we prefer to wrap the one line C++ has no problem with that. Hth, cmiiw
14th Mar 2018, 11:16 AM
Ipang
+ 2
if it contains only one statement we need not use {} in the"if statement". Otherwise we must use {}. If we didn't use syntax error will occur.
14th Mar 2018, 2:25 PM
Thomas Kurian
Thomas Kurian - avatar
0
Где русскии?
7th Apr 2019, 8:41 AM
артур чернобай