- Pascal 教程
- Pascal - 首頁
- Pascal - 概述
- Pascal - 環境設定
- Pascal - 程式結構
- Pascal - 基本語法
- Pascal - 資料型別
- Pascal - 變數型別
- Pascal - 常量
- Pascal - 運算子
- Pascal - 決策制定
- Pascal - 迴圈
- Pascal - 函式
- Pascal - 過程
- Pascal - 變數作用域
- Pascal - 字串
- Pascal - 布林值
- Pascal - 陣列
- Pascal - 指標
- Pascal - 記錄
- Pascal - 變體
- Pascal - 集合
- Pascal - 檔案處理
- Pascal - 記憶體
- Pascal - 單元
- Pascal - 日期和時間
- Pascal - 物件
- Pascal - 類
- Pascal 有用資源
- Pascal - 快速指南
- Pascal - 有用資源
- Pascal - 討論
Pascal - 布林運算子
下表顯示了 Pascal 語言支援的所有布林運算子。所有這些運算子都作用於布林運算元併產生布爾結果。假設變數A為真,變數B為假,則 -
| 運算子 | 描述 | 示例 |
|---|---|---|
| and | 稱為布林 AND 運算子。如果兩個運算元都為真,則條件變為真。 | (A and B) 為假。 |
| and then | 它類似於 AND 運算子,但是它保證了編譯器評估邏輯表示式的順序。從左到右,只有在必要時才評估右側運算元。 | (A and then B) 為假。 |
| or | 稱為布林 OR 運算子。如果兩個運算元中的任何一個為真,則條件變為真。 | (A or B) 為真。 |
| or else | 它類似於布林 OR,但是它保證了編譯器評估邏輯表示式的順序。從左到右,只有在必要時才評估右側運算元。 | (A or else B) 為真。 |
| not | 稱為布林 NOT 運算子。用於反轉其運算元的邏輯狀態。如果條件為真,則邏輯 NOT 運算子將使其變為假。 | not (A and B) 為真。 |
以下示例說明了該概念 -
program beLogical;
var
a, b: boolean;
begin
a := true;
b := false;
if (a and b) then
writeln('Line 1 - Condition is true' )
else
writeln('Line 1 - Condition is not true');
if (a or b) then
writeln('Line 2 - Condition is true' );
(* lets change the value of a and b *)
a := false;
b := true;
if (a and b) then
writeln('Line 3 - Condition is true' )
else
writeln('Line 3 - Condition is not true' );
if not (a and b) then
writeln('Line 4 - Condition is true' );
end.
當以上程式碼編譯並執行時,它會產生以下結果 -
Line 1 - Condition is not true Line 2 - Condition is true Line 3 - Condition is not true Line 4 - Condition is true
pascal_operators.htm
廣告