Top  | Previous | Next

Logic / switch

switch(value, case1, ...caseN, return1, ...returnN, returnDefault)

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.

 

switch(

15, // value

1,  // case 1

24, // case 2

15, // case 3

44, // return 1

45, // return 2

46, // return 3

-1) // default

...would return 46 because the value (15) matched case 3, so the third return (46) was returned.

 

switch(

35, // value

50,  // case 1

52, // case 2

200, // return 1

100, // return 2

-1) // default

...would return -1 because the value (35) didn't match case 1 or 2, so the returnDefault was used.

 

switch(

1, // value

0, 1, 2,  // cases 1-3

"Off"// return 1

"Running"// return 2

"Fault", // return 3

forceQuality("!BAD STATE!",0)) // default

...would return "Running".