if 语句包含一个布尔表达式,后跟一个或多个语句。

if - 语法

if {boolean_expression} {
   # statement(s) will execute if the Boolean expression is true
}

if - 流程图

If Statement

if - 示例

#!/usr/bin/tclsh

set a 10
 
#使用 if 语句检查布尔条件
if { $a < 20 } {
   # 如果条件为真,则打印以下内容
   puts "a is less than 20" 
}
puts "value of a is : $a" 

编译并执行上述代码后,将产生以下输出-

a is less than 20
value of a is : 10

参考链接

https://www.learnfk.com/tcl-tk/tcl-if-statement.html