contents.gifindex.gifprev1.gifnext1.gif

Toggle

Purpose

Creates and/or sets a memory variable to have the state ON or OFF, and returns a value associated with the state. See Notes.

Arguments

Toggle(

<var_name>
//The name of a memory variable. If this variable does not exist, it is instantiated.
, <init state>
// "ON" or "OFF". If the variable had no prior value, or is newly instantiated, it is assigned this value.
, <on_test>
// An expression evaluating to TRUE or FALSE.
, <off_test>
// An expression evaluating to TRUE or FALSE.
, <on_result>
// An expression evaluating to a value.
, <off_result>
// An expression evaluating to a value.
)

Notes

The function behavior is:

If required, apply init_state value.

If the value of the variable is "OFF", then:
if <on_test> is TRUE
set variable to "ON"
goto returnval

If the value of the variable is "ON", then:
if <off test> is TRUE
set variable to "OFF"
goto returnval

returnval:

//Variable now has a value.

If the value of the variable is "ON", then:
return <on_result>

If the value of the variable is "OFF", then:
return <off_result>

Note that all expressions in arguments are evaluated to values before the function body executes.