问题
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 )
{...}
}
回答1:
Yes. The if statement applies to the next statement after it - which happens to be another if in this case.
回答2:
Yes, they are equivalent
回答3:
Absolutely. Putting no brackets means that the only instruction in the first if is the other if, which can contains anything you want.
来源:https://stackoverflow.com/questions/4057827/nested-if-statements-without-brackets