Discussion:
Case statements
(too old to reply)
Mark
2004-01-22 13:59:32 UTC
Permalink
I am having my first experiences with case statements at the moment.
I am trying to read in a number, the case staement will place the
number in a range and force an output. This works fine with the
following:

1..5:writeln('Blah');
6..10:writeln('blah2');

I was wondering if it is possible to then manipulate the number
specific to that range.
i.e.

1..5:writeln('Blah');
something:=number*10;
6..10:writeln('blah2');
something:=number*11;

Is this possible? Thank you for any help
Mark
Jose Perez
2004-01-22 18:17:49 UTC
Permalink
Post by Mark
I am having my first experiences with case statements at the moment.
I am trying to read in a number, the case staement will place the
number in a range and force an output. This works fine with the
1..5:writeln('Blah');
6..10:writeln('blah2');
I was wondering if it is possible to then manipulate the number
specific to that range.
i.e.
1..5:writeln('Blah');
something:=number*10;
6..10:writeln('blah2');
something:=number*11;
Assuming that number is the variable being used in the case statement, yes,
this is a valid way to go. But why ask here? It's easy enough to try.
Post by Mark
Is this possible? Thank you for any help
Mark
bluewolf
2004-01-25 12:15:29 UTC
Permalink
Post by Mark
I am having my first experiences with case statements at the moment.
I am trying to read in a number, the case staement will place the
number in a range and force an output. This works fine with the
1..5:writeln('Blah');
6..10:writeln('blah2');
I was wondering if it is possible to then manipulate the number
specific to that range.
i.e.
1..5:writeln('Blah');
something:=number*10;
6..10:writeln('blah2');
something:=number*11;
Is this possible? Thank you for any help
Mark
program testcase;
uses crt;
var
tst : byte;
begin
write('Enter a number 1-20');readln(tst);
case tst of
1..5 : begin
writeln; writeln('You choose a number between 1 and 5..');
writeln('I will be adding 4 to that number.');
inc(tst,4);
end;
6..10 : begin
writeln('You number is: ',tst);
writeln('I'll add 3 to that number?!');
inc(tst,3);
end;
end;
writeln('After all that you ended up with the number',tst);
readln;
end.
--
-Onic B.B.S. List - http://plain.solidbox.com/bbslist/ *under
construction*
-Simple B.B.S. - telnet://plain.solidbox.com
Continue reading on narkive:
Loading...