Tcl Library Source Code

Documentation
Login


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

control - Procedures for control flow structures.

Table Of Contents

SYNOPSIS

package require Tcl 8.5 9
package require control ?0.1.4?

control::control command option ?arg arg ...?
control::assert expr ?arg arg ...?
control::do body ?option test?
control::no-op ?arg arg ...?

DESCRIPTION

The control package provides a variety of commands that provide additional flow of control structures beyond the built-in ones provided by Tcl. These are commands that in many programming languages might be considered keywords, or a part of the language itself. In Tcl, control flow structures are just commands like everything else.

COMMANDS

LIMITATIONS

Several of the commands provided by the control package accept arguments that are scripts to be evaluated. Due to fundamental limitations of Tcl's catch and return commands, it is not possible for these commands to properly evaluate the command [return -code $code] within one of those script arguments for any value of $code other than ok. In this way, the commands of the control package are limited as compared to Tcl's built-in control flow commands (such as if, while, etc.) and those control flow commands that can be provided by packages coded in C. An example of this difference:

% package require control
% proc a {} {while 1 {return -code error a}}
% proc b {} {control::do {return -code error b} while 1}
% catch a
1
% catch b
0

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category control of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.

SEE ALSO

break, continue, expr, if, join, namespace, return, string, while

KEYWORDS

assert, control, do, flow, no-op, structure

CATEGORY

Programming tools