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配对,如果没有标识符。。。
这个问题,真的是太容易范了。。。