Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 3/Boolean Expressions/zh CN: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
113B - 布尔表达式 (原作者: Tao Yue, 状态: 未更改)
22
33[[Boolean/zh CN|布尔表达式]] 用于比较两个值,得到 `真` 或者 `假`:
44
5-```
5+```text
66值1 关系运算符 值2
77```
88
99使用以下关系运算符:
1010
11-```
11+```text
1212< 小于
1313> 大于
1414= 等于
1515<= 小于等于
1616>= 大于等于
1717<> 不等于
1818```
1919
2020你可以将运算结果赋值给变量,这里我们将一个 `真` 赋值给 some_bool。
2121
2222``` pascal
2323some_bool := 3 < 5;
2424```
2525
2626逻辑运算符:
2727
28-```
28+```text
2929not 逻辑非 (~)
3030and 逻辑与 (^)
3131or 逻辑或 (v)
3232xor 逻辑异或
3333```
3434
3535`NOT`是一元运算符,用于取反。
3636
3737- not 真 = 假
3838- not 假 = 真
3939
4040`AND`,当两个值都为真是,结果为真,否则为假。
4141
4242- 真 and 假 = 假
4343- 真 and 真 = 真
4444
4545`OR`,当有一个值为真时,结果为真,否则为假。
4646
4747- 真 or 真 = 真
4848- 真 or 假 = 真
4949- 假 or 真 = 真
5050- 假 or 假 = 假
5151
5252`XOR`,任一值为真时,结果为真,但不能同时是,从而:
5353
5454- 真 xor 真 = 假
5555- 真 xor 假 = 真
5656- 假 xor 真 = 真
5757- 假 xor 假 = 假
5858
5959当关系运算符和逻辑运算符混合使用时,要小心使用括号。
6060
6161``` pascal
6262(3>5) or (650<1)
6363```
6464
6565`逻辑运算符` 优先级高于 `关系运算符`:
6666
67671. not
68682. * / div mod and
69693. \+ - or
70704. \< \> \<= \>= = \<\>
7171
7272所以,`3 > 5 or 650`,运算时,是这样:`3 > (5 or 650)`,但这样没有意义,因为整数不适用逻辑运算。
7373
7474逻辑运算符(`AND、OR、NOT、XOR`),可以很容易在逻辑表达式上使用。
7575
7676如有可能,不要使用等号比较2个实数,因为,小数位会导致它们不相等。
7777
7878| | | |
7979|----|----|----|
8080| [[Basic Pascal Tutorial/Chapter 3/Sequential control/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 3/IF/zh CN|下一页]] |
8181
8282---
8383*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 3/Boolean Expressions/zh CN", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history