跳轉到內容

Ada 程式設計/關鍵字/and

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

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

邏輯運算子

[編輯 | 編輯原始碼]

布林運算子

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

布林短路運算子

[編輯 | 編輯原始碼]

短路運算子用於使布林表示式的部分評估條件化:and then, or else。這永遠不應該用於加快評估速度(使用現代最佳化編譯器,它可能不會產生這種效果)。正確的用法是防止評估已知會引發異常的表示式。

if Dog /= null and then G (Dog) then
   Walk (Dog);
end if;

在上面的例子中,G (Dog)僅在指標Dog不為null時呼叫,即它實際上指向某處。

實際上,and thenor else 並不是參考手冊意義上的運算子,它們被稱為“短路控制形式”。區別在於(true)運算子可以重新定義(即過載),而這些則不能。但是,它們被定義為任何布林型別。

由於 Ada 允許並行評估表示式引數,因此短路運算子不是評估布林表示式的標準方式。在任何最終結果保證相同的情況下,編譯器被允許使用短路評估。

陣列上的布林運算子

[編輯 | 編輯原始碼]

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

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 and Y;

按位運算子

[編輯 | 編輯原始碼]

運算子 and 可與 模型別 一起使用來執行按位操作。

向帶標籤型別新增介面

[編輯 | 編輯原始碼]

此語言特性僅從 Ada 2005 開始可用。

type Programmer is new Person 
                   and Printable
with 
   record
     Skilled_In : Language_List;
   end record;

華夏公益教科書

[編輯 | 編輯原始碼]

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
delay 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
華夏公益教科書