if语句包含一个布尔表达式后跟一个或多个语句。
Tcl语言的if语句的语法是:
if {boolean_expression} { |
# statement(s) will execute if the boolean expression is true |
} |
如果代码里布尔表达式的值为真,那么if语句块将被执行。如果 if 语句的结束(右大括号后)布尔表达式的值为false,那么第一套代码会被执行。
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