GNU Octave Manual Version 3 by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |
10.2.1 Notes for the C programmer
The switch
statement is also available in the widely used C
programming language. There are, however, some differences
between the statement in Octave and C
-
Cases are exclusive, so they don't `fall through' as do the cases
in the
switch
statement of the C language. -
The command_list elements are not optional. Making the list
optional would have meant requiring a separator between the label and
the command list. Otherwise, things like
switch (foo) case (1) -2 ...
would produce surprising results, as wouldswitch (foo) case (1) case (2) doit (); ...
particularly for C programmers. Ifdoit()
should be executed if foo is either1
or2
, the above code should be written with a cell array like thisswitch (foo) case { 1, 2 } doit (); ...
ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |