Pascal · lesson 9 of 30 · Decisions and loopsChoose with case
case compares one value with letters, lists and ranges.
09-case.pas Download 09-case.pas
program Menu;
var
Choice: Char;
begin
WriteLn('s: space t: temperature q: stop');
Write('Choice: ');
ReadLn(Choice);
case Choice of
's', 'S': WriteLn('1.2 TB free');
't', 'T': WriteLn('38 C');
'q': WriteLn('Stopped');
'0'..'9': WriteLn('Type a letter, not a digit');
else
WriteLn('There is no choice ', Choice);
end;
end.
Terminal
$ ./09-case
s: space t: temperature q: stop
Choice: t
38 C
$ ./09-case
s: space t: temperature q: stop
Choice: 5
Type a letter, not a digitExercise
Add a choice h that prints a help line.