with Ada.Text_IO,Ada.Integer_Text_IO;
use Ada.Text_IO,Ada.Integer_Text_IO;
procedure Compares is
package Enum_IO is new Ada.Text_IO.Enumeration_IO(Boolean);
use Enum_IO;
Index,Count :Integer :=12;
Truth,Lies,Question :Boolean;
begin
Truth :=Index=Count; -- this is true
Lies :=Index<Index; -- this is false
-- example of all boolean operators
Question:=Index=Count; -- equality
Question:=Index/=Count; -- Inequality
Question:=Index>=Count; -- greater than or equal
Question:=Index<=Count; -- less than or equal
Question:=Index>Count; -- greater than
Question:=Index<Count; -- less than
-- example of all boolean operators
Question:=Index=12 and Count=12 and Truth and True;
Question:=Index/=12 or False or Count>3 or Truth;
Question:=(Truth or Lies) and (Truth and not Lies);
Question:=True xor Lies;
-- now for short circuit evaluation
Question:=Index/=Count and then Index = 9/(Index-Count);
Question:=Index=Count or else Index=9/(Index-Count);
Question:=(Index=Count) or else (Index=9/(Index-Count));
end Compares;
013.复杂的boolean表达式
最新推荐文章于 2022-11-05 14:23:26 发布
本文深入探讨了Ada语言中布尔运算符的使用,包括等号、不等号、大于等于、小于等于、大于和小于运算符,以及逻辑与、或、非、异或运算符的应用。通过具体实例展示了短路评估的原理。
546

被折叠的 条评论
为什么被折叠?



