DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

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 )
                {...}
 }

Upvotes: 4

Views: 3626

Answers (3)

lbedogni
lbedogni

Reputation: 8007

Absolutely. Putting no brackets means that the only instruction in the first if is the other if, which can contains anything you want.

Upvotes: 1

xscott
xscott

Reputation: 2420

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

Upvotes: 5

Armen Tsirunyan
Armen Tsirunyan

Reputation: 133024

Yes, they are equivalent

Upvotes: 3

Related Questions