camdo2
11-04-2007, 04:07 AM
First off I would like to thank floor66 for teaching me on cases for my old script.
What is a case?
A case is like a procedure that does something like picking one of the choices you give it out of a hat. That's the very basics. I will now tell you how to begin your case.
Program CaseTUT;
begin
case random(2) of
0: begin
Writeln('good job');
end;
1: begin
Writeln('learning on cases');
end;
end;
end;
Let's look at each of these things:
random(2) means that the number in the parenthesis will be the number of options that you put in the case.
0: is the first option
1: is the second option
But this kind of thing can be used for many reasons which all of them I don't know. One I know of though is an auto typer can pick random sentences. There is also a function I believe named FindFastRandoms that uses cases too.
If you put a loop in here, it will keep repeating the picking of a hat. Like this...
program loopcasetut;
begin
repeat
case random(3) of
0: begin
Writeln('good job');
end;
1: begin
Writeln('learning on cases');
end;
2: begin
Writeln('so far');
end;
end;
until(false);
end;
okay... We know that the repeat in bold is repeat and the until(false) at the end will repeat the case forever! The only thing I changed about this is that the number in the random() is instead of 2 it's 3. What this will do instead of the program having two choices to pick from it will have three.
I hope this helps...
-Camdo Clark
What is a case?
A case is like a procedure that does something like picking one of the choices you give it out of a hat. That's the very basics. I will now tell you how to begin your case.
Program CaseTUT;
begin
case random(2) of
0: begin
Writeln('good job');
end;
1: begin
Writeln('learning on cases');
end;
end;
end;
Let's look at each of these things:
random(2) means that the number in the parenthesis will be the number of options that you put in the case.
0: is the first option
1: is the second option
But this kind of thing can be used for many reasons which all of them I don't know. One I know of though is an auto typer can pick random sentences. There is also a function I believe named FindFastRandoms that uses cases too.
If you put a loop in here, it will keep repeating the picking of a hat. Like this...
program loopcasetut;
begin
repeat
case random(3) of
0: begin
Writeln('good job');
end;
1: begin
Writeln('learning on cases');
end;
2: begin
Writeln('so far');
end;
end;
until(false);
end;
okay... We know that the repeat in bold is repeat and the until(false) at the end will repeat the case forever! The only thing I changed about this is that the number in the random() is instead of 2 it's 3. What this will do instead of the program having two choices to pick from it will have three.
I hope this helps...
-Camdo Clark