跳轉到內容

Ada 程式設計/關鍵字/or

來自華夏公益教科書,開放書籍,構建開放世界

Ada. Time-tested, safe and secure.
Ada. 經久考驗,安全可靠。

邏輯運算子

[編輯 | 編輯原始碼]

布林運算子

[編輯 | 編輯原始碼]
X : Boolean := A < 10 or A > 20;

布林簡短運算子

[編輯 | 編輯原始碼]

在下面的示例中,函式G僅在F(X)返回的值為False時呼叫。

if F(X) or else G(Y) then

    Walk_The_Dog;
 
end if;

這個簡短運算子有時用於加速布林表示式的求值,但Ada 風格指南建議在切換到另一個之前比較兩種形式的效能。通常,使用or else 僅當第二個表示式涉及函式呼叫時,才出於效能原因。

當第二個表示式已知會引發異常(除非第一個表示式為False)時,也會使用or else 形式。

與 C/C++ 不同,Ada 簡短運算子不是求值布林表示式的標準方式。這是因為 Ada 預設情況下旨在執行通常更安全的操作,但允許程式設計師請求不同的行為。

陣列上的布林運算子

[編輯 | 編輯原始碼]

or 運算子應用於來自左側和右側陣列的每個布林元素對。結果與左側運算元具有相同的邊界。

type Day_Of_Month is range 1 .. 31;            
type Month_Array is array (Day_Of_Month) of Boolean;

X : Month_Array := Function_1;
Y : Month_Array := Function_2;
Z : Month_Array := X or Y;

按位運算子

[編輯 | 編輯原始碼]

運算子 or 可與 模型別 一起使用以執行按位運算。

選擇語句

[編輯 | 編輯原始碼]

參見 Ada 程式設計/任務#選擇性等待.

參見 Ada 程式設計/任務#超時.

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 95 參考手冊

[編輯 | 編輯原始碼]

Ada 2005 參考手冊

[編輯 | 編輯原始碼]

Ada 質量和風格指南

[編輯 | 編輯原始碼]


Ada 關鍵字
abort else new return
abs elsif not reverse
abstract (Ada 95) end null
accept entry select
access exception of separate
aliased (Ada 95) exit or some (Ada 2012)
all others subtype
and for out synchronized (Ada 2005)
array function overriding (Ada 2005)
at tagged (Ada 95)
generic package task
begin goto parallel (Ada 2022) terminate
body pragma then
if private type
case in procedure
constant interface (Ada 2005) protected (Ada 95) until (Ada 95)
is use
declare raise
延遲 limited range when
delta loop record while
digits rem with
do mod renames
requeue (Ada 95) xor


Ada 運算子
and and then > + abs &
or or else >= - mod
xor = < * rem in
not /= <= ** / not in
華夏公益教科書