case

case is used in switch statements and specifies a constant expression, expression, that the variable used in switch is compared with. The expression in each case label must be a constant and unique in the scope of the switch statement.

Syntax

case(expression)

Inputs

expression
A constant, unique expression used in the case label of a switch statement.
Type: int | log

Example


y = 1;
x = 2 * y;
switch (x)
case 1
disp ('x is equal to 1');
case 2
disp ('x is equal to 2');
otherwise
disp ('x does not equal 1 or 2');
end
x is equal to 2