November 1999
Intermediate to advanced
832 pages
19h 28m
English
The if command is the basic conditional command. If an expression is true, then execute one command body; otherwise, execute another command body. The second command body (the else clause) is optional. The syntax of the command is:
if expression ?then? body1 ?else? ?body2?
The then and else keywords are optional. In practice, I omit then but use else as illustrated in the next example. I always use braces around the command bodies, even in the simplest cases:
if {$x == 0} {
puts stderr "Divide by zero!"
} else {
set slope [expr $y/$x]
}
|
![]() | Curly brace positioning is important. |
The ...
Read now
Unlock full access