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

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

技术教程推荐

邱岳的产品手记 -〔邱岳〕

邱岳的产品实战 -〔邱岳〕

技术管理实战36讲 -〔刘建国〕

白话法律42讲 -〔周甲徳〕

Vue开发实战 -〔唐金州〕

互联网人的英语私教课 -〔陈亦峰〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

分布式数据库30讲 -〔王磊〕

零基础学Python(2023版) -〔尹会生〕

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