Switch Statement
The switch statement is similar to the if/else if/else structure. However, rather than choosing a branch to execute based on a binary condition, the Switch chooses a branch (i.e., a case) based on a value.
var day = CALC.weekdayname(CALC.today())
switch(day) {
case 'Sunday':
Text1.text = 'Note: ' + day + ' office closed.';
break;
case 'Thursday':
case 'Friday':
case 'Saturday':
Text1.text = 'Note: ' + day + ' hours are 10am-12pm.';
break;
default:
Text1.text = 'Note: ' + day + ' hours are 9am-5pm.'
break;
}
Note that one or more values can be listed on each case (e.g., Thursday, Friday, Saturday). A 'break' statement should be included at the end of each case to terminate the switch statement.
The “default” label at the end serves as the catch-all case. If the switch value does not match any of the explicit case values, then the “default” block is executed.
| << While Loop | © 1996-2013 InetSoft Technology Corporation (v11.4) | Functions >> |