60 likes | 136 Views
Case … of …. grade?. grade = ‘F’. grade = ‘B’. grade = ‘A’. grade = ‘D’. display “very good”. display “good”. display “fair”. display “poor”. case grade of ‘A’ : writeln(‘very good’); ‘B’ : writeln(‘good’); ‘D’ : writeln(‘fair’); ‘F’ : writeln(‘poor’); end;.
E N D
grade? grade = ‘F’ grade = ‘B’ grade = ‘A’ grade = ‘D’ display “very good” display “good” display “fair” display “poor”
case grade of ‘A’ : writeln(‘very good’); ‘B’ : writeln(‘good’); ‘D’ : writeln(‘fair’); ‘F’ : writeln(‘poor’); end;
case <selector(integer/char/boolean)> of <case label 1> : <statement 1>; <case label 2> : <statement 2>; … <case label N> : <statement N>; end;
Example 1 case number of 2,3,5,7 : numbertype:=‘prime’; 4,6,8,9,10 : numbertype:=not prime’; end;
Example 2 case letter of ‘F’,’f’ : begin female:=female + 1; writeln(‘one female’); end; ‘M’,’m’:begin male:=male+1; writeln(‘one male’); end; end;