Revision 1 of 2, by Trev on 2-17-2020. The page as it is now.
If/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;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.
