case..of statement | range a..b



case..of statement | range a..b
Pas2JS pascal source code
procedure WriteLnIntRange(const value : Integer); begin case value of -2..-1 : WriteLn('negative'); 0 : WriteLn('zero'); 5, 10 : WriteLn('multiple of five'); 1..4, 6..9 : WriteLn('between 1 and 9 but 5'); else WriteLn('elsewhere'); end; end; var i : Integer; BEGIN for i:=-3 to 11 do begin WriteLn(IntToStr(i)+Chr(32)); WriteLnIntRange(i); end; case 'Hello' of 'Bonjour'..'Icare' : WriteLn('Hello!'); 'Alpha'..'Omega' : WriteLn('oopsie!'); else WriteLn('oopsie!'); end; { ### CONSOLE OUTPUTS ### -3 elsewhere -2 negative -1 negative 0 zero 1 between 1 and 9 but 5 2 between 1 and 9 but 5 3 between 1 and 9 but 5 4 between 1 and 9 but 5 5 multiple of five 6 between 1 and 9 but 5 7 between 1 and 9 but 5 8 between 1 and 9 but 5 9 between 1 and 9 but 5 10 multiple of five 11 elsewhere Hello! }