SRL Archive - Help and Support

Case Statements...


Pancakes

2007-10-17 22:38:33

Well, just as an example, this won't work:

case Random(100) of
1-10: //Do this.
40-60: //Do this:
>60: //Do this.
end;

I think you can see what I'm trying to get at, using case statements decide on what to to. Like if the level is between 1-10, do something, if it is between 40-60 do something else, if it is over 60 do something else.

This can be accomplished using if…then's but I feel it would be alot easier using case statements. Thanks. :)

pwnaz0r

2007-10-17 23:13:34

just do this.


var i: integer;
begin
i:= random(100);
if (I >= 0) or (I<=40)then
//etc...

EDIT: be sure to note that 0 is a valid integer.

Bobarkinator

2007-10-17 23:55:44

If you wanted to do it in a case statement, you would have to do this:
case Random(100) of
0,1,2,3,4,5,6,7,8,9,10: //Do this.
40,41,42,43,44,45,46....59,60: //Do this:
61,62,63,64,65....98,99: //Do this.
end;

You can't have the "…."'s in their. You would have to declare every number.

Pancakes

2007-10-18 01:04:44

@pwnaz0r: Yeah, I know, but it gets messy when you have say, 50+ if statements like that.
@Bob: I was afraid of that, I already knew that but I was wondering if there was a way to include all the numbers… like with arrays. Oh well.

Cheers,
~Pancakes

n3ss3s

2007-10-18 03:24:08

Use InRange -.-

Though I would also like something "1-10"

Pancakes

2007-10-18 03:49:42

Jeez thanks, didn't even think of that one :)

Cheers!

Santa_Clause

2007-10-18 06:09:53

procedure LoadRandomWaits;
var
I, J, K : Integer;
begin
for I := 1 to 10 do
for J := 40 to 60 do
for K := 61 to 100 do
case Random(100) of
I : //Do this.
J : //Do this:
K : //Do this.
end;
end;

Pancakes

2007-10-18 06:13:25

Eh wtf does that do lol… so many loops inside loops lol. *Brain explodes*

Santa_Clause

2007-10-18 06:30:33

For all the numbers from 1 to 10 (I) it does something. For 40 to 60 (J) it does something else. Same with K.

The Claw

2007-10-18 07:04:32

From: Pancakes
Well, just as an example, this won't work:

case Random(100) of
1-10: //Do this.
40-60: //Do this:
>60: //Do this.
end;

I think you can see what I'm trying to get at, using case statements decide on what to to. Like if the level is between 1-10, do something, if it is between 40-60 do something else, if it is over 60 do something else.

This can be accomplished using if…then's but I feel it would be alot easier using case statements. Thanks. :)


could you possibly do [1..10], [40..60], and [60..100]? im not sure but maybe lol

Jason2gs

2007-10-18 11:06:24

Well, you can assign a random value to an integer, and use logical operators in the case statement, but why do you need such a high range of numbers?

program New;
var
i: Integer;

begin
i := Random(9);
case i of
0: Writeln('Zero');
4: Writeln('Four');
5: Writeln('Five');
i > 5: Writeln('Five to Nine');
end;
end.

Seems to give the same odds…

Edit:

Seems I spoke too soon. "i > 5" only seems to return true if i is equal to five. That doesn't seem right :|

The Un-Named

2007-10-18 13:10:18

As far as I know, operators don't work in case statements, at least, not as they should.

Pancakes

2007-10-18 17:51:15

Ah thats gay, I'll just stick to using InRange I guess.

R0b0t1

2007-10-18 19:09:28

Have you tried it array style? [0..100]?