Share

IF - ELSEIF - ELSE statement

The IF - ELSEIF - ELSE statement executes a series of commands when a certain condition is met, a different series of commands when the first condition is not met and the second condition is met and a different series of commands when none of the conditions are met.

The basic control structure is:

IF <expression_1> {
    Commands A
}   ELSEIF <expression_2> {
    Commands B
}   ELSE {
    Commands C
}
Commands D

If expression_1 is true, then Commands A are executed followed by Commands D.

If expression_1 is false and expression_2 is true, then Commands B are executed followed by Commands D.

If expression_1 is false and expression_2 is false, then Commands C are executed followed by Commands D.

image

Tip: ELSE is an optional statement. There may be any number of ELSEIF statements in a block but no more than one ELSE.
IF Tool.Type == "end_mill" OR Tool.Type == "ball_nosed" {
    $radius = Tool.Diameter/2
}   ELSEIF active(Tool.TipRadius) {
    $radius = Tool.TipRadius
}   ELSE {
    $radius = 0
    PRINT "Invalid tool type"
}

This sets the variable radius to:

  • Half the tool diameter if the tool is an end mill or ball nosed tool.

  • The tip radius if the tool is a tip radiused tool.

  • Displays Invalid tool type if the tool is anything else.

Was this information helpful?