switch
This function acts like the switch statement in C-like programming languages. It takes the value argument and compares it to each of the case1 through caseN expressions. If value is equal to caseX , then switch returns valueX . If value is not equal to any of the case1..N , then returnDefault is returned.
Note that switch() is similar in functionality to the case() expression function . The difference between the two is the order in which the parameters are passed.
switch( value, case1, ...caseN, return1, ...returnN, returnDefault )
//The following would return 46 because the value (15) matched case 3, so the third return (46) was returned.
switch
(
15
,
// value
1
,
// case 1
24
,
// case 2
15
,
// case 3
44
,
// return 1
45
,
// return 2
46
,
// return 3
-
1
)
// default
//The following would return "Running".
switch
(
1
,
// value
0
,
1
,
2
,
// cases 1-3
"Off"
,
// return 1
"Running"
,
// return 2
"Fault"
,
// return 3
forceQuality(
"!BAD STATE!"
,
0
))
// default