Specifications

Software Crestron SIMPL+
today = getDayNum(); // gets the current day of the week
if (today = 0) // is today Sunday?
{
// code to run on Sundays
}
else if (today = 5) // is today Friday?
{
// code to run on Friday
}
else if (today = 6) // is today Saturday?
{
// code to run on Saturdays
}
else // only gets here if the first three
{ // conditions are false
// code to run on all other days
}
NOTE: There can be as many if-else statements in a single construct as necessary.
However, sometimes tasks like these are better handled with the switch - case
construct, discussed in the next section.
Finally, note that if statements can be nested inside other if statements.
switch–case
In the last section, it was shown that the if-else construct can be used for making
complex decisions. Also it was used for making a choice between mutually exclusive
conditions (conditions that cannot coexist), the syntax can become cumbersome. For
this particular case SIMPL+ offers the switch-case construct.
Think of switch-case as a compact way of writing an if-else construct. The basic
form of the switch-case is shown after this paragraph.
switch (expression)
{
case (expression1):
{
// code here executes if
// expression = expression1
}
case (expression2):
{
// code here executes if
// expression = expression2
}
default:
{
// code here executes if none
// of the above cases are true
}
}
NOTE: The use of the default keyword allows specific code to execute if none of
the other cases are true. This is identical to the final else statement in the if-else
construct mentioned in “if–else”.
26 SIMPL+
Programming Guide – DOC. 5789A