Difference between revisions of "If/zh CN"
From Lazarus wiki
Jump to navigationJump to searchm (Text replace - "delphi>" to "syntaxhighlight>") |
m (Fixed syntax highlighting; deleted category included in page template) |
||
Line 3: | Line 3: | ||
== If then(条件语句) == | == If then(条件语句) == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
if condition | if condition | ||
then statement1 | then statement1 | ||
Line 17: | Line 17: | ||
注意:1. else 之前不能加分号。下面是不合法的: | 注意:1. else 之前不能加分号。下面是不合法的: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
if condition | if condition | ||
then statement1; | then statement1; | ||
Line 25: | Line 25: | ||
2.else 总是与和它最近的if配对: | 2.else 总是与和它最近的if配对: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
if condition1 | if condition1 | ||
then if condition2 then statement1; | then if condition2 then statement1; | ||
Line 37: | Line 37: | ||
要使else与第一个if配对,则应写成这样: | 要使else与第一个if配对,则应写成这样: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
if condition | if condition | ||
then begin | then begin | ||
Line 52: | Line 52: | ||
If语句可以使用复合语句 ([[Begin|begin]] ... [[End|end]] [[Block]])。 | If语句可以使用复合语句 ([[Begin|begin]] ... [[End|end]] [[Block]])。 | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
if boolean_condition then | if boolean_condition then | ||
begin | begin | ||
Line 63: | Line 63: | ||
{{Keywords}} | {{Keywords}} | ||
− |
Latest revision as of 10:38, 17 February 2020
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
中文(中国大陆) (zh_CN) │
If then(条件语句)
if condition
then statement1
else statement2;
Condition 是布尔表达式
如果 Condition 为真则执行 statement1,否则执行 statement2。
Else 和 statement2 可省略,此时如 Condition 为假则跳过 if 语句。
注意:1. else 之前不能加分号。下面是不合法的:
if condition
then statement1;
else statement2;
2.else 总是与和它最近的if配对:
if condition1
then if condition2 then statement1;
else statement2;
上面的else与第二个if配对;
要使else与第一个if配对,则应写成这样:
if condition
then begin
if condition2 then statement1;
end
else statement2;
If语句中使用复合语句
If语句可以使用复合语句 (begin ... end Block)。
if boolean_condition then
begin
statement1;
statement2;
statement3;
end;
Keywords: begin — do — else — end — for — if — repeat — then — until — while