switch
Just like an if-else statement but can only compare one variable. Each possibility is represented with a 'case' with the default case being 'otherwise'.
Syntax
switch (X)
case a
statement
case b
otherStatement;
otherwise
otherOtherStatement;
end
Inputs
- case
- Logical case for each possible switch statement.
- otherwise
- Default case if none of the other case conditions are met.
Outputs
- statement
- Executed if case condition is met.
Example
Simple switch statement:
switch (X)
case 1
print ('X = 1');
case 2
print ('X = 2');
otherwise
print ('X does not equal 1 or 2');
end