Tcl - 嵌套 Switch 语句
可以将 switch 作为外部 switch 语句序列的一部分。 即使内部和外部开关的大小写常量包含共同值,也不会发生冲突。
语法
嵌套 switch 语句的语法如下 −
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

tcl_decisions.html