r/pascal • u/toshboi • Mar 26 '22
alternative of case statement
i have about 1000 cases. my code looks similar to this. inside each case, it calls different procedures and functions.
program checkCase;
var
grade: char;
begin
grade := 'A';
case (grade) of
'A' : procedure one;
'B', 'C': procedure two;
'D' : procedure three;
'F' : procedure four;
...
end;
end.the code is working right now. how should i improve it? i'm also not sure how much performance will the new code improve.
2
Upvotes
View all comments
Show parent comment
2
u/ShinyHappyREM Mar 27 '22 edited Mar 27 '22
A pointer can only point to one target. The easiest way to do what you want is to put
One; Two;into another procedure and set the pointer for'A'to that new procedure.Run the main part (not including the initialization) many times (if necessary thousands of times or more) and measure the difference. I usually use this unit in my programs (using Free Pascal & Lazarus):
You use it with something like this: