Sign in Join
Wiki copytemporary

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

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
113B - 布尔表达式 (原作者: Tao Yue, 状态: 未更改)
22
33[[Boolean/zh CN|布尔表达式]] 用于比较两个值,得到 `真` 或者 `假`:
44
55`值1 `**`关系运算符`**` 值2`
66
77使用以下关系运算符:
88
99`<  小于`\
1010`>  大于`\
1111`=  等于`\
1212`<= 小于等于`\
1313`>= 大于等于`\
1414`<> 不等于`
1515
1616你可以将运算结果赋值给变量,这里我们将一个 `真` 赋值给 some_bool。
1717
1818`some_bool := 3 < 5;`
1919
2020逻辑运算符:
2121
2222`not    逻辑非 (~)`\
2323`and    逻辑与 (^)`\
2424`or    逻辑或 (v)`\
2525`xor    逻辑异或`
2626
2727`NOT`是一元运算符,用于取反。
2828
29-- <tt>not 真 = 假
30-- not 假 = 真</tt>
29+- not 真 = 假
30+- not 假 = 真
3131
3232`AND`,当两个值都为真是,结果为真,否则为假。
3333
34-- <tt>真 and 假 = 假
35-- 真 and 真 = 真</tt>
34+- 真 and 假 = 假
35+- 真 and 真 = 真
3636
3737`OR`,当有一个值为真时,结果为真,否则为假。
3838
39-- <tt>真 or 真 = 真
39+- 真 or 真 = 真
4040- 真 or 假 = 真
4141- 假 or 真 = 真
42-- 假 or 假 = 假</tt>
42+- 假 or 假 = 假
4343
4444`XOR`,任一值为真时,结果为真,但不能同时是,从而:
4545
46-- <tt>真 xor 真 = 假
46+- 真 xor 真 = 假
4747- 真 xor 假 = 真
4848- 假 xor 真 = 真
49-- 假 xor 假 = 假</tt>
49+- 假 xor 假 = 假
5050
5151当关系运算符和逻辑运算符混合使用时,要小心使用括号。
5252
5353``` pascal
5454(3>5) or (650<1)
5555```
5656
5757`逻辑运算符` 优先级高于 `关系运算符`:
5858
59-1. <tt>not
59+1. not
60602. * / div mod and
61613. \+ - or
62-4. \< \> \<= \>= = \<\></tt>
62+4. \< \> \<= \>= = \<\>
6363
6464所以,`3 > 5 or 650`,运算时,是这样:`3 > (5 or 650)`,但这样没有意义,因为整数不适用逻辑运算。
6565
6666逻辑运算符(`AND、OR、NOT、XOR`),可以很容易在逻辑表达式上使用。
6767
6868如有可能,不要使用等号比较2个实数,因为,小数位会导致它们不相等。
6969
7070| | | |
7171|----|----|----|
7272| [[Basic Pascal Tutorial/Chapter 3/Sequential control/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 3/IF/zh CN|下一页]] |
7373
7474---
7575*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