MATLAB: Or-function with switch

or for case

Can you not use or in one of the cases for switch. I tried here but it did not call it at all:
I know about the case {2, 3} possibility just wondered about if or is a possibility here
here is my function:
function grade=switchletgrade1(quiz)
if quiz<0 ||quiz>4
grade='X'
else
switch quiz
case 3 || 2
grade='B'
case 4
grade='A'
otherwise
grade='C'
end
end
end

Best Answer

No, 3||2 cannot be used in that context. Each case list is executed (unless the switch matched earlier), so 3||2 as a case label is evaluated as logical(3)||logical(2) which is true||true which is true which has the numeric value 1. Coding 3||2 as a case is thus equivalent to coding a 1 at that point.
The {} notation is the one you need for multiple possibilities.