Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select Case
#11
There is no way.

In old BASICs you could do something like:

Code:
GOTO 1000 + 100 * choice

this ain't possible in any version of MS BASIC as far as I know.

You have the ON choice GOTO label1, label2, label3..., but it translates roughly to the same code as a SELECT CASE. So it's better to use SELECT CASE just 'cause it's more readable and structured programming is the best solution 99% of the time.

The best solution to your problem would be what has been suggested. Profile your program and place the most likely cases first. Anyway, the assembly generated on a SELECT case is very optimized. You speak about 20 different cases on average. That would make, in the worst case, 20 simple expression evaluations and 20 short jumps. That's not a lot of time. If you are that concerned about optimization, just precalculate every expression in your CASEs.

There is a rule of thumb: finding a better algorithm is always better than optimizing a not so good one.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#12
Quote:the assembly generated on a SELECT case is very optimized

I agree, every case has only a compare and a jump
I guess I am just paranoid about time wasted.

FWIW I di manage to create a small asm routine (12 clks) that would jump to any calculated label.

On a seperate subject.
Quote:Bandwidth Limit Exceeded
The server is temporarily unable to service your request due to the site owner reaching his/her bandwidth limit. Please try again later.
--------------------------------------------------------------------------------

Apache/1.3.34 Server at forum.qbasicnews.com Port 80

Has the site been off the air for the last few hours. ?
t is the End result that matters, not the Tools used to get there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)