> Date: Thu, 13 Jan 2005 10:31:56 +0000
> From: Anthony Stone <[log in to unmask]>
> I have a program in which I use the structure
>
> go to (101,102,103,104,105,106,107,108,109,110), index
> 110 stuff
> ...
> 109 more stuff
> ...
> 108 and so on
> ...
> ...
>
> The computed GOTO used here is an obsolescent feature, but there
> doesn't seem to be an obvious replacement. A CASE construct isn't
> suitable, because there is no jump out at the end of each block --
> execution falls through to the next block, as in C, so if (say)
> index=9, the blocks of code labelled 108, 107 etc are to be executed
> as well as the block labelled 109. Each block is quite large, so
> repeating them is not sensible. I could get the same result using the
> code
I wouldn't worry about computed GOTO at this stage.
It won't go away any time soon, and it is clear and neat
in this case.
If you want to change it, your SELECT construct is about as good
as you can get.
Alternatively, you could place the 10 actions at 101, 102, etc.
in ten CONTAINed procedures.
You could then use a SELECT construct containing CALLs
to those procedures. For some actions, more than one CALL
would be required to satisfy the special requirements of your
code.
> select case (index)
> case(10)
> goto 110
> case(9)
> goto 109
> ...
> end select
>
> but that is horribly clumsy. Arranging the blocks in the reverse order
> and testing index after each one is a bit better but still relatively
> clumsy.
>
> Is there a neat way to do what I want without using the computed GOTO?
> Could it be that (horrors) the computed GOTO has some uses after all?
> --
> Anthony Stone http://www-stone.ch.cam.ac.uk/
|