<< parsestring | Interpreter functions | try >> |
switch(expression), case test_expression_1, statements, case test_expression_2, statements, otherwise statements, end |
switch statement is used to selective execute code based on the value of either scalar value or a string.
otherwise clause is optional.
demo_switch.m
function c = demo_switch(a)
switch(a)
case {'hello', 'world'}
c = 'message';
case {'red', 'green', 'blue'}
c = 'color';
otherwise
c = 'not sure';
end
end
demo_switch('hello')
demo_switch('red')
demo_switch('?')
for.
Version | Description |
---|---|
1.0.0 | initial version |
Allan CORNET