IF/zh CN: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
Title: If/zh CN IF/zh CN
| Old | New | | Line |
|---|
| 1 | | - | ## If then(条件语句) |
| 2 | | - | |
| 3 | | - | ``` pascal |
| 4 | | - | if condition |
| 5 | | - | then statement1 |
| 6 | | - | else statement2; |
| 7 | | - | ``` |
| 8 | | - | |
| 9 | | - | Condition 是布尔表达式 |
| 10 | | - | |
| 11 | | - | 如果 Condition 为真则执行 statement1,否则执行 statement2。 |
| 12 | | - | |
| 13 | | - | Else 和 statement2 可省略,此时如 Condition 为假则跳过 if 语句。 |
| 14 | | - | |
| 15 | | - | 注意:1. else 之前不能加分号。下面是不合法的: |
| 16 | | - | |
| 17 | | - | ``` pascal |
| 18 | | - | if condition |
| 19 | | - | then statement1; |
| 20 | | - | else statement2; |
| 21 | | - | ``` |
| 22 | | - | |
| 23 | | - | 2.else 总是与和它最近的if配对: |
| 24 | | - | |
| 25 | | - | ``` pascal |
| 26 | | - | if condition1 |
| 27 | | - | then if condition2 then statement1; |
| 28 | | - | else statement2; |
| 29 | | - | ``` |
| 30 | | - | |
| 31 | | - | 上面的else与第二个if配对; |
| 32 | | - | |
| 33 | | - | 要使else与第一个if配对,则应写成这样: |
| 34 | | - | |
| 35 | | - | ``` pascal |
| 36 | | - | if condition |
| 37 | | - | then begin |
| 38 | | - | if condition2 then statement1; |
| 39 | | - | end |
| 40 | | - | else statement2; |
| 41 | | - | ``` |
| 42 | | - | |
| 43 | | - | ### If语句中使用复合语句 |
| 44 | | - | |
| 45 | | - | If语句可以使用复合语句 ([[Begin|begin]] ... [[End|end]] [[Block]])。 |
| 46 | | - | |
| 47 | | - | ``` pascal |
| 48 | | - | if boolean_condition then |
| 49 | | - | begin |
| 50 | | - | statement1; |
| 51 | | - | statement2; |
| 52 | | - | statement3; |
| 53 | | - | end; |
| 54 | | - | ``` |
| 55 | | - | |
| 56 | | - | --- |
| 57 | | - | *From the Free Pascal wiki, page "If/zh CN", as it stood on 2020-02-17 after a change by Trev, 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).* |
| 1 | + | #REDIRECT [[Basic Pascal Tutorial/Chapter 3/IF/zh CN]] |
Back to history