在Tcl语言while循环,只要给定的条件为真,执行目标语句声明多次。
在Tcl语言while循环的语法是:
while {condition} {
   statement(s)
}
	在这里,声明(S)可以是单个语句或语句块。所述条件可以是任何表达,真是指任何非零值。循环迭代当条件为真。
当条件为假,则程序控制进到紧接在循环之后的代码行。
在这里,while循环的关键点是,当条件测试结果为假时,在循环可能不会永远运行。循环体将跳过while循环后的第一个语句将被执行。
#!/usr/bin/tclsh
set a 10
#while loop execution 
while { $a < 20 } {
   puts "value of a: $a"
   incr a
}
当上述代码被编译和执行时,它产生了以下结果:
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
