Basic Pascal Tutorial/Chapter 3/CASE/zh CN

From Free Pascal wiki
(Redirected from CASE/zh CN)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

български (bg) English (en) español (es) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

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

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

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

if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then
  语句1
else
  语句2;

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

case b of
  1,7,2037,5: 语句1;
  else   语句2
end;

CASE语句的格式是:

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.

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

上一页 目录 下一页