Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / share / tcl / help / tcl / control / if
1 NAME
2 if - Execute scripts conditionally
3
4 SYNOPSIS
5 if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ... ?else?
6 ?bodyN?
7
8
9 DESCRIPTION
10 The if command evaluates expr1 as an expression (in the same way that
11 expr evaluates its argument). The value of the expression must be a
12 boolean (a numeric value, where 0 is false and anything is true, or a
13 string value such as true or yes for true and false or no for false);
14 if it is true then body1 is executed by passing it to the Tcl inter-
15 preter. Otherwise expr2 is evaluated as an expression and if it is
16 true then body2 is executed, and so on. If none of the expressions
17 evaluates to true then bodyN is executed. The then and else arguments
18 are optional ``noise words'' to make the command easier to read. There
19 may be any number of elseif clauses, including zero. BodyN may also be
20 omitted as long as else is omitted too. The return value from the com-
21 mand is the result of the body script that was executed, or an empty
22 string if none of the expressions was non-zero and there was no bodyN.
23
24 EXAMPLES
25 A simple conditional:
26 if {$vbl == 1} { puts "vbl is one" }
27
28 With an else-clause:
29 if {$vbl == 1} {
30 puts "vbl is one"
31 } else {
32 puts "vbl is not one"
33 }
34
35 With an elseif-clause too:
36 if {$vbl == 1} {
37 puts "vbl is one"
38 } elseif {$vbl == 2} {
39 puts "vbl is two"
40 } else {
41 puts "vbl is not one or two"
42 }
43
44 Remember, expressions can be multi-line, but in that case it can be a
45 good idea to use the optional then keyword for clarity:
46 if {
47 $vbl == 1 || $vbl == 2 || $vbl == 3
48 } then {
49 puts "vbl is one, two or three"
50 }
51
52
53 SEE ALSO
54 expr(n), for(n), foreach(n)
55
56
57 KEYWORDS