Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 3/CASE/zh CN

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

3Cb - CASE语句 (原作者: Tao Yue, 状态: 未更改)

根据条件执行CASE语句。CASE语句计算每个表达式,以进行选择,它可以是常量、范围,或将它们以逗号分隔的列表。用冒号分隔每个语句块。

假设一种分支方式是:如b是1、7、2037、5,你可以这样:

pascal
if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then
  ??????1
else
  ??????2;

在这种情况下,使用CASE语句会变得简单:

pascal
case b of
  1,7,2037,5: ??????1;
  else   ??????2
end;

CASE语句的格式是:

pascal
case ????????? of
  ??????1:    ??????1;
  ??????2:    ??????2;
  ...
  ??????n:    ??????n;
  else ??????;
end;

else部分是可选的,else表示其他情况。

选择器是一个有序数据类型的任何变量,但不能使用实数。

Note that the lists must consist of literal values. That is, you must use constants or hard-coded values -- you cannot use variables.

(注意,该列表必须包含文本值。也就是说,您必须使用常量或硬编码值——您不能使用变量。)

上一页 目录 下一页

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 3/CASE/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 1, 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
Swen (minor)
Wangyouworld (minor)
FTurtle
TrevFixed syntax highlighting; deleted category already in page template (minor)
Kai BurghardtKai Burghardt moved page CASE/zh CN to Basic Pascal Tutorial/Chapter 3/CASE/zh CN: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Clutt... (minor)
Kai Burghardtbypass redirects [cf. discussion]
Kai Burghardtbypass [previously missed] redirect [cf. discussion]
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.