12.5.10    elseif

Description:   The elseif command expression will be executed when the if statement is false and the elseif statement is true..

Syntax:         if expr1 then body1 elseif expr2 then body2

if expr1 then body1 elseif expr2 then body2 else bodyN

If expr1 then body1 elseif expr2 then body2 elseif

 

Argument:     logical expression and command  

Returns:        The return value from the command is the result of the body script that was executed.

See Also:       if, else

 

Examples:     

catch {

 

if {[GETVAL AMPLITUDE] < 0} then {

   SETVAL {AMPLITUDE=%LOOPPLUS 10}

} elseif {[GETVAL AMPLITUDE] < [GETVAL AMPLITUDE.OUTPHI]} then {

   SETVAL {AMPLITUDE=%LOOPPLUS @tag1}

} else {

   SETVAL {AMPLITUDE=@AMPLITUDE.OUTPLO}

}

}

# ramps value up to output high limit.  if value less than 0, increase by 10, else increase by value of tag1 until output high limit reached, then reset to output low limit.

This command is used with if statement to produce nested if commands. The elseif command expression will be executed when the if statement is false and the elseif statement is true.  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 {

 

 

} elseif {} then {

 

 

} else {

 

 

}

 

Hint -  If you use the script editor dialog box keywords,  and double click on if, then double click on elseif, it will position the if, then elseif with line breaks appropriately so they always work.