Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested if-statements without brackets

following code is given:

       if (c2-c1==0)
        if ( c1 != c3 )
                    {...}

How do I interpret this code? The first if-statement comes without {}. Is the code above equal to the following code?:

 if (c2-c1==0){
    if ( c1 != c3 )
                {...}
 }
like image 693
UpCat Avatar asked Jan 21 '23 04:01

UpCat


2 Answers

Yes. The if statement applies to the next statement after it - which happens to be another if in this case.

like image 52
xscott Avatar answered Feb 01 '23 16:02

xscott


Yes, they are equivalent

like image 23
Armen Tsirunyan Avatar answered Feb 01 '23 18:02

Armen Tsirunyan