SRL Archive - OSR Help

Case Structure


Sk1nyNerd

2014-02-20 18:48:19

Can somebody give a detailed example or a tut link on how to make a case structure so i dont have to do a situation like this:

Procedure SetVariables;
Begin

If (bank = 'blah') then
Begin
bankcolors := [313,232];
end else
If (bank = 'blahblah') then
Begin
bankcolors := [444,323];
end else
If (bank = 'blahblahblah') then
Begin
bankcolors := [232.234234];
end;

If (log = 'bum') then
Begin
logcolors := [313,232];
end else
If (log = 'bumbum') then
Begin
logcolors := [444,323];
end else
If (log = 'bumbumbum') then
Begin
logcolors := [232,234234];
end;

end;

thanks, im getting too lost following variables in other peoples code

Olly

2014-02-20 18:57:03

const
bank = 'blah3';

var
bankColors, logColors: array [0..1] of integer;

begin
case bank of // case of what var? in this example we're comparing to string constant 'bank'.
'blah': bankColors := [0, 1]; // if 'blah' matches, then set the bank colors vars!

'blah2': bankColors := [1, 2];

'blah3': begin // you can also use a begin and a end if you have multiple things you want to do.
writeln('blah 3!');
bankColors := [3, 4];
end;
end; // each case needs a end!

writeln(bankColors);
end.

Does that help?

Sk1nyNerd

2014-02-20 21:18:11

From: Olly
const
bank = 'blah3';

var
bankColors, logColors: array [0..1] of integer;

begin
case bank of // case of what var? in this example we're comparing to string constant 'bank'.
'blah': bankColors := [0, 1]; // if 'blah' matches, then set the bank colors vars!

'blah2': bankColors := [1, 2];

'blah3': begin // you can also use a begin and a end if you have multiple things you want to do.
writeln('blah 3!');
bankColors := [3, 4];
end;
end; // each case needs a end!

writeln(bankColors);
end.

Does that help?


exactly, thanks Olly

Frement

2014-02-21 00:46:05

Don't you need to break after each clause?

Brandon

2014-02-21 01:44:18

From: Frement
Don't you need to break after each clause?


Pascal has no break for cases. Only end or semi-colon can suffice. An else statement is the equivalent of "default".

masterBB

2014-02-21 15:59:10

Try use LowerCase when comparing strings to create more foolproof functions:

case LowerCase(bank) of

Sk1nyNerd

2014-02-21 16:35:38

From: masterBB
Try use LowerCase when comparing strings to create more foolproof functions:

case LowerCase(bank) of


does that force the text to lowercase or is it telling it that the text is lowercase and to ignore uppercase? i thought upper and lower didnt make a big deal

rj

2014-02-21 16:51:15

From: Sk1nyNerd
does that force the text to lowercase or is it telling it that the text is lowercase and to ignore uppercase? i thought upper and lower didnt make a big deal


When it comes to comparing strings it is

begin
writeln('Hello' = 'hello');
writeln('hello' = 'hello');
writeln(lowerCase('Hello') = 'hello');
end.

Results:

False
True
True

Sk1nyNerd

2014-02-21 16:58:30

From: Officer Barbrady
When it comes to comparing strings it is

begin
writeln('Hello' = 'hello');
writeln('hello' = 'hello');
writeln(lowerCase('Hello') = 'hello');
end.

Results:

False
True
True


cool,thanks