Sign in Join
Wiki copytemporary

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

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

Title: Basic Pascal Tutorial/Chapter 3/Boolean Expressions/zh CN

OldNewLine
1+3B - 布尔表达式 (原作者: Tao Yue, 状态: 未更改)
2+
3+[[Boolean/zh CN|布尔表达式]] 用于比较两个值,得到 `真` 或者 `假`:
4+
5+`值1 `**`关系运算符`**` 值2`
6+
7+使用以下关系运算符:
8+
9+`<  小于`\
10+`>  大于`\
11+`=  等于`\
12+`<= 小于等于`\
13+`>= 大于等于`\
14+`<> 不等于`
15+
16+你可以将运算结果赋值给变量,这里我们将一个 `真` 赋值给 some_bool。
17+
18+`some_bool := 3 < 5;`
19+
20+逻辑运算符:
21+
22+`not    逻辑非 (~)`\
23+`and    逻辑与 (^)`\
24+`or    逻辑或 (v)`\
25+`xor    逻辑异或`
26+
27+`NOT`是一元运算符,用于取反。
28+
29+- <tt>not 真 = 假
30+- not 假 = 真</tt>
31+
32+`AND`,当两个值都为真是,结果为真,否则为假。
33+
34+- <tt>真 and 假 = 假
35+- 真 and 真 = 真</tt>
36+
37+`OR`,当有一个值为真时,结果为真,否则为假。
38+
39+- <tt>真 or 真 = 真
40+- 真 or 假 = 真
41+- 假 or 真 = 真
42+- 假 or 假 = 假</tt>
43+
44+`XOR`,任一值为真时,结果为真,但不能同时是,从而:
45+
46+- <tt>真 xor 真 = 假
47+- 真 xor 假 = 真
48+- 假 xor 真 = 真
49+- 假 xor 假 = 假</tt>
50+
51+当关系运算符和逻辑运算符混合使用时,要小心使用括号。
52+
53+``` pascal
54+(3>5) or (650<1)
55+```
56+
57+`逻辑运算符` 优先级高于 `关系运算符`:
58+
59+1. <tt>not
60+2. * / div mod and
61+3. \+ - or
62+4. \< \> \<= \>= = \<\></tt>
63+
64+所以,`3 > 5 or 650`,运算时,是这样:`3 > (5 or 650)`,但这样没有意义,因为整数不适用逻辑运算。
65+
66+逻辑运算符(`AND、OR、NOT、XOR`),可以很容易在逻辑表达式上使用。
67+
68+如有可能,不要使用等号比较2个实数,因为,小数位会导致它们不相等。
69+
70+| | | |
71+|----|----|----|
72+| [[Basic Pascal Tutorial/Chapter 3/Sequential control/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 3/IF/zh CN|下一页]] |
73+
74+---
75+*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