位置:首页 » 文章/教程分享 » TCL continue语句

Tcl语言中continue语句的工作有点像break语句。但不是强制终止,但是,继续强制循环的下一个迭代发生,跳过中间的代码。

对于for循环,continue语句使循环的条件测试和增量部分执行。对于while循环,continue语句通过程序控制的条件测试。

语法

在Tcl continue语句的语法如下:

continue;

流程图

Continue Statement

示例

#!/usr/bin/tclsh

set a 10
# do loop execution 
while { $a < 20 } {
   if { $a == 15} {
     #skip the iteration 
	 incr a
     continue
   }
   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: 16
value of a: 17
value of a: 18
value of a: 19