If/zh CN

From Free Pascal wiki
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.

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: begindoelseendforifrepeatthenuntilwhile