2016年合欢树价格表:关于Pascal中选择结构的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/09 00:03:56
有个关于Pascal的选择结构的问题。
为什么
if(a<b)and(b<c) then 语句1
else 语句2;
这段程序与
if a<b then
if b<c then语句1
else语句2
不等效,而是与
if a<b then begin
if b<c then 语句1
else 语句2;
end
else 语句3;
这个是等效的?

请注意,else是和离它最近的if配套的。所以
if a<b then
if b<c then语句1
else语句2
意味着,当a<b且b>=c时,执行语句2,和
if(a<b)and(b<c) then 语句1
else 语句2;
就不是一个意思了。