Previous topic | Ada Home Page | Index

Case example


-- Fintan Culwin Sept '88 v1.0
-- program to illustrate case selection
-- see text p121

with TEXT_IO;
use  TEXT_IO;

procedure demo_case is

   ch  : CHARACTER;     -- char to classify

begin -- of demo_case 

   -- get char from user
   PUT ( "Enter character> ");
   GET ( ch ); SKIP_LINE;

   -- case structure to classify a single character
   case ch is			-- classify ch
      when '?' =>			-- demo single value
         PUT_LINE("is a question mark");
      when '!' =>
         PUT_LINE("is an exclamation mark");
      when 'A' .. 'Z' =>	-- demo use of range
         PUT_LINE("is upper case");
      when 'a' .. 'z' =>
         PUT_LINE("is lower case");
      when '0' .. '9' =>
         PUT_LINE("is a digit");
      when '.' | ',' | ';' | ':' =>	-- list of alts
         PUT_LINE("is punctuation");
      when others =>	-- do nothing for other values of ch
         null;
   end case;
end demo_case;


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 13 Feb 96