Description: The else command body will be executed when the if statement is false.
Syntax: if expr1 then body1 else bodyN
if expr1 then body1 elseif expr 2 then body2 else bodyN
Argument: command or body of commands
Returns: The return value from the command is the result of the body script that was executed.
See Also: if, elseif, Calculation Tag
Examples:
catch {
if {[GETVAL AMPLITUDE] < [GETVAL AMPLITUDE.OUTPHI]} then {
SETVAL {AMPLITUDE=%LOOPPLUS @tag1} } else {
SETVAL {AMPLITUDE=@AMPLITUDE.OUTPLO}
}
}
# same as above but with indenting
catch {
if {[GETVAL AMPLITUDE] < [GETVAL AMPLITUDE.OUTPHI]
} then {
SETVAL {AMPLITUDE=%LOOPPLUS @tag1}
} else {
SETVAL {AMPLITUDE=@AMPLITUDE.OUTPLO}
}
}
This else command is used with if statement and invoked at end of an if command. The else command expression will be executed when the if statement is false. Else can be omitted from if statement if the bodyN command is omitted.
Tcl is very picky about spaces and line breaks. The if-then-else statements seem to work best when if and then are on same line, and the else is on same line as the then command body.
if {} then {
} else {
}
Hint: if you use the script editor dialog box keywords, and double click on if, then double click on else (or elseif), it will position the if, then else with line breaks appropriately so they always work.