Tcl 中的 嵌套if语句函数

首页 / Tcl/Tk入门教程 / Tcl 中的 嵌套if语句函数

在Tcl中, nest if-else语句始终是合法的,这意味着您可以在另一个if or else if语句中使用一个if or else if语句。

nested 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 。

无涯教程网

nested if - 示例

#!/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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

程序员进阶攻略 -〔胡峰〕

代码精进之路 -〔范学雷〕

Go语言从入门到实战 -〔蔡超〕

许式伟的架构课 -〔许式伟〕

分布式技术原理与算法解析 -〔聂鹏程〕

MongoDB高手课 -〔唐建法(TJ)〕

Service Mesh实战 -〔马若飞〕

PyTorch深度学习实战 -〔方远〕

云时代的JVM原理与实战 -〔康杨〕

好记忆不如烂笔头。留下您的足迹吧 :)