Introduction
Control constructs are the building blocks of an action. In this chapter, we will explore the creation of procedures, as well as managing the flow of events.
Prior to the creation of constructs the programmer's primary tool was the goto
statement. While this allowed recursive handling of conditions and minimized impact on memory usage, it resulted in non-modular code and added substantially to the overhead of debugging and maintenance.
In Tcl, as in all programming languages, a control construct is a command that instructs the program to perform a certain action (or actions) based on a predefined condition. How many times the action (or actions) is/are performed is based on the specific construct used. For example, an if
statement will perform the pre-defined actions once, whereas a while
statement will perform the actions until the condition is no longer met.
Tcl has a full contingent of control constructs. The basic usages or descriptions of these commands are as follows...