The switch-case construct provides a more elegant solution to
Example 4.2 as can be seen from the following code:
selection-2.m
% A switch-case example
day = input(‘Enter a number for the day ( 1 to 7)’)
disp (‘The day is :’ )
switch(day)
case 1
disp (‘Monday’)
case 2
disp (‘Tuesday’)
case 3
disp (‘Wednesday’)
case 4
disp (‘Thursday’)
case 5
disp (‘Friday’)
case 6
disp (‘Saturday’)
case 7
disp (‘Sunday’)
otherwise
disp (‘Not a valid entry for the day’)
end
4.3 Loops
A loop is a structure for repeating certain set ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.