IF: if expression1 [then] THEN-body |
|
Always use
{ ... }
to enclose all expressions and bodies of the
if statement !!!
(Because, you need to make a single word and more importantly, you must learn to prevent evaluation before passing in the arguments to be evaluated - this will become important in the while statement that repeatedly evaluates an expression !) ) |
set x 4 |
Syntax 1: unquoted switch STRING match-pattern1 body1 .... match-patternn bodyn |
This guarantees that some set of code will be executed no matter what the contents of string are.
|
set z abc
switch $x {
$z {
puts "MATCH \$z."
}
ONE {
puts "MATCH ONE."
}
default {
puts "$x is NOT A MATCH"
}
}
|
set z abc
switch $x \
$z {
puts "MATCH case \$z ($z)."
} \
{$z} {
puts "MATCH case {\$z} (\$z literally)."
} \
ONE {
puts "MATCH case ONE."
} \
default {
puts "$x is NOT A MATCH"
}
|