Continuing a procedure
While the continue
keyword is not a control construct in itself, it allows you to affect the control flow.
How to do it…
In the following recipe, we will create a Tcl script, to be called from the command line, that increments the value of x
and prints out the value as in the for
command recipe. However, the output will be skipped when x
is equal to 5.
Create a text file named continue.tcl
that contains the following commands.
Please note that within the comparison used to invoke the continue
keyword, I have added a blank line for clarification. This is not needed for the continue
statement but does make the output more legible as well as illustrating the usage of conditional check to perform additional actions.
for {set x 1} {$x < 11} {incr x} { if {$x == 5} { puts " " continue } puts "x = $x" }
Now invoke the script using the following command line:
% tclsh85 continue.tcl x = 1 x = 2 x = 3 x = 4 x = 6 x = 7 x = 8 x = 9 x = 10
How it works…
The action was invoked 10...