在Tcl中, nest if-else语句始终是合法的,这意味着您可以在另一个if or else if语句中使用一个if or else if语句。
if { boolean_expression 1 } { # Executes when the boolean expression 1 is true if {boolean_expression 2} { # Executes when the boolean expression 2 is true } }
您可以像嵌套 if 语句一样,嵌套 else if ... else 。
#!/usr/bin/tclsh set a 100 set b 200 # check the boolean condition if { $a == 100 } { # if condition is true then check the following if { $b == 200 } { #if condition is true then print the following puts "Value of a is 100 and b is 200" } } puts "Exact value of a is : $a" puts "Exact value of b is : $b"
编译并执行上述代码后,将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tcl-nested-if-statements.html
来源:LearnFk无涯教程网
Value of a is 100 and b is 200 Exact value of a is : 100 Exact value of b is : 200
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)