Nested if-statements without brackets

非 Y 不嫁゛ 提交于 2019-12-23 12:09:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!