Case of 语句

Case of 语法

case(expression) of
   L1 : S1;
   L2: S2;
   ...
   ...
   Ln:Sn;
end;

L1-Ln 可以使用 整数 字符 布尔 枚举 这几种类型

case语句必须有一个end语句与之关联。

流程图

case statement

官方样例

program checkCase;
var
   grade:char;
begin
   grade :='A';
   case(grade) of
      'A': writeln('Excellent!');
      'B','C': writeln('Well done');
      'D': writeln('You passed');
      'F': writeln('Better try again');
   end;     
   writeln('Your grade is  ', grade );
end.
运行结果
Excellent!
Your grade is A

Case of else 语句

case(expression) of
   L1 : S1;
   L2 : S2;
   ...
   ...
   Ln:Sn;
else
   Sm;
end;

流程图

else case statement

官方样例
program checkCase;
var
   grade:char;
begin
   grade :='F';
   case(grade) of
      'A': writeln('Excellent!');

      'B','C': writeln('Well done');
      'D': writeln('You passed');
   else
      writeln('You really did not study right!');
    end;     
   writeln('Your grade is  ', grade );
end.
运行结果
You really did not study right!
Your grade is F

Case of else 嵌套语句

嵌套语句由于比较复杂,不适合新手教学,所以不多做解释,需要看的可以查看下面的连接

https://www.pilotlogic.com/sitejoom/index.php/wiki/105-wiki/pascal-basics/chapter-2/133-pascal-nested-case-statements.html

Copyright © 280i.com 2020 all right reserved,powered by Gitbook本书建立时间: 2020-04-07 19:41:37

results matching ""

    No results matching ""