TCL if语句

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

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3