case - else statement
优质
小牛编辑
132浏览
2023-12-01
case-else语句在case标签之后使用else术语,就像if-then-else结构一样。
语法 (Syntax)
case-else语句的语法是 -
case (expression) of
L1 : S1;
L2 : S2;
...
...
Ln: Sn;
else
Sm;
end;
流程图 (Flow Diagram)
例子 (Example)
以下示例说明了该概念
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