Tcl If 语句
if 语句由布尔表达式后跟一个或多个语句组成。
语法
在Tcl语言中,’if’语句的语法如下所示-
if {boolean_expression} {
# statement(s) will execute if the Boolean expression is true
}
如果布尔表达式的值为 true ,那么在 if 语句内的代码块将被执行。如果布尔表达式的值为 false ,那么在’if’语句结束后(即右花括号之后)的第一组代码将被执行。
Tcl语言在内部使用 expr 命令,所以我们不需要显式使用 expr 语句。
流程图
示例
#!/usr/bin/tclsh
set a 10
#check the boolean condition using if statement
if { a<20 } {
# if condition is true then print the following puts "a is less than 20"
}
puts "value of a is :a"
当上面的代码被编译和执行时,它产生以下结果−
a is less than 20
value of a is : 10