- Pascal 教程
- Pascal - 主頁
- Pascal - 概述
- Pascal - 環境設定
- Pascal - 程式結構
- Pascal - 基本語法
- Pascal - 資料型別
- Pascal - 變數型別
- Pascal - 常量
- Pascal - 運算子
- Pascal - 決策
- Pascal - 迴圈
- Pascal - 函式
- Pascal - 過程
- Pascal - 變數範圍
- Pascal - 字串
- Pascal - 布林值
- Pascal - 陣列
- Pascal - 指標
- Pascal - 記錄
- Pascal - 變體
- Pascal - 集合
- Pascal - 檔案處理
- Pascal - 記憶體
- Pascal - 單元
- Pascal - 日期和時間
- Pascal - 物件
- Pascal - 類
- Pascal 有用的資源
- Pascal - 快速指南
- Pascal - 有用的資源
- Pascal - 討論
Pascal - 巢狀 Case 語句
在外部 case 語句 的語句序列中,可以有一個 case 語句。即使內部和外部 case 的 case 常量 包含常見值,也不會出現衝突。
語法
巢狀 case 語句的語法如下 −
case (ch1) of
'A': begin
writeln('This A is part of outer case' );
case(ch2) of
'A': writeln('This A is part of inner case' );
'B': (* case code *)
...
end; {end of inner case}
end; (* end of case 'A' of outer statement *)
'B': (* case code *)
'C': (* case code *)
...
end; {end of outer case}
示例
以下程式說明了該概念。
program checknestedCase;
var
a, b: integer;
begin
a := 100;
b := 200;
case (a) of
100: begin
writeln('This is part of outer statement' );
case (b) of
200: writeln('This is part of inner statement' );
end;
end;
end;
writeln('Exact value of a is : ', a );
writeln('Exact value of b is : ', b );
end.
當編譯並執行上述程式碼時,它會產生以下結果 −
This is part of outer switch This is part of inner switch Exact value of a is: 100 Exact value of b is: 200
pascal_decision_making.htm
廣告