Tcl - Continue Statement



The continue statement in Tcl language works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.

For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while loop, continue statement passes the program control to the conditional tests.

Syntax

The syntax for a continue statement in Tcl is as follows −

continue;

Flow Diagram

Continue Statement

Example

#!/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     
}

When the above code is compiled and executed, it produces the following result −

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
tcl_loops.htm
Advertisements