if的辩论

来源:互联网 发布:宝塔系统 加密 php 编辑:程序博客网 时间:2024/04/29 13:22

If statements have a famous problem. In the following piece of code, is the statement-2executed or not?

if 语句的问题:状态2 会被执行吗?

if (1>0)

    if(1<0)

        statement -1

else

    statment-2

The answer is that it is. Ignore the indentation (which is misleading). The else could belong to either the first or second if, according to the description of the if statement that has just been given, so an extra rule is needed to make it unambiguous. 

else被赋予最近的if配对,如果没有标识符。。。

这个问题,真的是太容易范了。。。