Basic Pascal Tutorial/Chapter 3/CASE/zh CN: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | 3Cb - CASE语句 (原作者: Tao Yue, 状态: 未更改) | |
| 2 | 2 | ||
| 3 | 3 | 根据条件执行CASE语句。CASE语句计算每个表达式,以进行选择,它可以是[[Const/zh CN|常量]]、范围,或将它们以[[Comma/zh CN|逗号]]分隔的列表。用[[Colon/zh CN|冒号]]分隔每个语句块。 | |
| 4 | 4 | ||
| 5 | 5 | 假设一种分支方式是:如`b`是`1、7、2037、5`,你可以这样: | |
| 6 | 6 | ``` | |
| 7 | 7 | if (b = 1) or (b = 7) or (b = 2037) or (b = 5) then | |
| 8 | 8 | 语句1 | |
| 9 | 9 | else | |
| 10 | 10 | 语句2; | |
| 11 | 11 | ``` | |
| 12 | 12 | ||
| 13 | 13 | 在这种情况下,使用`CASE语句`会变得简单: | |
| 14 | 14 | ``` | |
| 15 | 15 | case b of | |
| 16 | 16 | 1,7,2037,5: 语句1; | |
| 17 | 17 | else 语句2 | |
| 18 | 18 | end; | |
| 19 | 19 | ``` | |
| 20 | 20 | ||
| 21 | 21 | `CASE语句`的格式是: | |
| 22 | 22 | ``` | |
| 23 | 23 | case 选择器 of | |
| 24 | 24 | 列表1: 语句1; | |
| 25 | 25 | 列表2: 语句2; | |
| 26 | 26 | ... | |
| 27 | 27 | 列表n: 语句n; | |
| 28 | 28 | else 语句; | |
| 29 | 29 | end; | |
| 30 | 30 | ``` | |
| 31 | 31 | ||
| 32 | 32 | `else`部分是可选的,`else`表示其他情况。 | |
| 33 | 33 | ||
| 34 | 34 | 选择器是一个有序数据类型的任何变量,但不能使用实数。 | |
| 35 | 35 | ||
| 36 | 36 | Note that the lists must consist of literal values. That is, you must use constants or hard-coded values -- you cannot use variables. | |
| 37 | 37 | ||
| 38 | 38 | (~~注意,该列表必须包含文本值。也就是说,您必须使用常量或硬编码值——您不能使用变量。~~ ) | |
| 39 | 39 | ||
| 40 | 40 | [[Basic Pascal Tutorial/Chapter 3/IF/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 3/FOR..DO/zh CN|下一页]] | |
| 41 | 41 | ---|---|--- | |
| 42 | 42 | ||
| 43 | 43 | --- | |
| 44 | - | ||
| 44 | + | *From the Free Pascal wiki, page "CASE/zh CN", as the Internet Archive kept it on 2023-03-22, last changed on 2022-08-20. 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).* |
