Tcl-tk-tcl-nested-switch-statements
提供:Dev Guides
Tcl-ネストされたスイッチステートメント
外部スイッチのステートメントシーケンスの一部として*スイッチ*を使用することができます。 内側と外側のスイッチのケース定数に共通の値が含まれていても、競合は発生しません。
構文
- ネストされたスイッチ*ステートメントの構文は次のとおりです-
switch switchingString {
matchString1 {
body1
switch switchingString {
matchString1 {
body1
}
matchString2 {
body2
}
...
matchStringn {
bodyn
}
}
}
matchString2 {
body2
}
...
matchStringn {
bodyn
}
}
例
#!/usr/bin/tclsh
set a 100
set b 200
switch $a {
100 {
puts "This is part of outer switch"
switch $b {
200 {
puts "This is part of inner switch!"
}
}
}
}
puts "Exact value of a is : $a"
puts "Exact value of a is : $b"
上記のコードをコンパイルして実行すると、次の結果が生成されます-
This is part of outer switch
This is part of inner switch!
Exact value of a is : 100
Exact value of a is : 200