Sign in Join
Wiki copytemporary

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

Sent here from Boolean Expressions/zh CN.

English · Français · Български · 中文(中国) · 日本語

3B - 布尔表达式 (原作者: Tao Yue, 状态: 未更改)

布尔表达式 用于比较两个值,得到 真 或者 假:

text
值1 关系运算符 值2

使用以下关系运算符:

text
<  小于
>  大于
=  等于
<= 小于等于
>= 大于等于
<> 不等于

你可以将运算结果赋值给变量,这里我们将一个 真 赋值给 some_bool。

pascal
some_bool := 3 < 5;

逻辑运算符:

text
not    逻辑非 (~)
and    逻辑与 (^)
or    逻辑或 (v)
xor    逻辑异或

NOT是一元运算符,用于取反。

AND,当两个值都为真是,结果为真,否则为假。

OR,当有一个值为真时,结果为真,否则为假。

XOR,任一值为真时,结果为真,但不能同时是,从而:

当关系运算符和逻辑运算符混合使用时,要小心使用括号。

pascal
(3>5) or (650<1)

逻辑运算符 优先级高于 关系运算符:

  1. not
    • / div mod and
  2. + - or
  3. < > <= >= = <>

所以,3 > 5 or 650,运算时,是这样:3 > (5 or 650),但这样没有意义,因为整数不适用逻辑运算。

逻辑运算符(AND、OR、NOT、XOR),可以很容易在逻辑表达式上使用。

如有可能,不要使用等号比较2个实数,因为,小数位会导致它们不相等。

上一页 目录 下一页

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.

Revision 4, last changed by WikiArchive .

Edited on wiki.freepascal.org by 5 people, 2013–2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
WangyouworldCreated page
Wangyouworld
Swen (minor)
FTurtle
TrevFixed syntax highlighting; deleted category already in page template (minor)
Kai BurghardtKai Burghardt moved page Boolean Expressions/zh CN to Basic Pascal Tutorial/Chapter 3/Boolean Expressions/zh CN: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[S... (minor)
Kai Burghardtbypass redirects [cf. discussion]
Kai Burghardtfix previous edit (minor)
Kai Burghardtbypass language bar/categorization template redirect [cf. discussion] (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.