首页 > 解决方案 > 您可以在伪代码的 if 语句中使用复合条件吗?

问题描述

例如这个简单的程序,它测试 3 个数字是否按升序排列

if a1<a2 then
 if a2<a3 then 
    write "the numbers are in ascending order";
 else 
    write "the numbers are not in ascending order";
 endif
else 
 write "the numbers are not in ascending order;
endif

我可以用伪代码这样写吗?

if (a1<a2 and a2<a3) 
  write "the numbers are in ascending order";
else 
  write "the numbers are not in ascending order";

标签: pseudocode

解决方案


是的。只要它是可以理解的并且可以很容易地转换为真正的源代码,它就可以作为伪代码。


推荐阅读