![]() |
|
|
|
#1 |
|
If I'm within a switch, then saying "case 10:" creates a sort of
label. Is it possible to jump directly to one of these, eg "goto case 12;"? I realise this can be done by adding a "normal" label next to the "case" label, and that it might be possible to arrange a similar thing by cunning use of fall-through or by changing the variable and executing the switch again, but is there a neat syntax to jump to one of the other cases? Thanks. Paul. Paul N |
|
|
|
|
#2 |
|
Posts: n/a
|
On Nov 2, 10:33*pm, Paul N <gw7...@aol.com> wrote:
> If I'm within a switch, then saying "case 10:" creates a sort of > label. Is it possible to jump directly to one of these, eg "goto case > 12;"? I realise this can be done by adding a "normal" label next to > the "case" label, and that it might be possible to arrange a similar > thing by cunning use of fall-through or by changing the variable and > executing the switch again, but is there a neat syntax to jump to one > of the other cases? > > Thanks. > Paul. A case expression is not a label (and in any case must be a constant). So there is no sort of label at all. Cheers paperab |
|
|
|
#3 |
|
Posts: n/a
|
Paul N wrote:
> If I'm within a switch, then saying "case 10:" creates a sort of > label. Is it possible to jump directly to one of these, eg "goto > case 12;"? I realise this can be done by adding a "normal" label > next to the "case" label, and that it might be possible to arrange > a similar thing by cunning use of fall-through or by changing the > variable and executing the switch again, but is there a neat syntax > to jump to one of the other cases? > > Thanks. > Paul. No. Perhaps the "neat" way is to factor the common code out to a separate function, and call that one from several locations. Bo Persson Bo Persson |
|
|
|
#4 |
|
Posts: n/a
|
Paul N wrote:
> If I'm within a switch, then saying "case 10:" creates a sort of > label. Is it possible to jump directly to one of these, eg "goto case > 12;"? I realise this can be done by adding a "normal" label next to > the "case" label, and that it might be possible to arrange a similar > thing by cunning use of fall-through or by changing the variable and > executing the switch again, but is there a neat syntax to jump to one > of the other cases? > > Thanks. > Paul. Create a function to call from the case and call that function. -- ------------ < I'm Karmic > ------------ \ \ ___ {~._.~} ( Y ) ()~*~() (_)-(_) Mick |
|
|
|
#5 |
|
Posts: n/a
|
"Bo Persson" <> wrote in message
news:... > Paul N wrote: >> If I'm within a switch, then saying "case 10:" creates a sort of >> label. Is it possible to jump directly to one of these, eg "goto >> case 12;"? I realise this can be done by adding a "normal" label >> next to the "case" label, and that it might be possible to arrange >> a similar thing by cunning use of fall-through or by changing the >> variable and executing the switch again, but is there a neat syntax >> to jump to one of the other cases? >> >> Thanks. >> Paul. > > No. > > Perhaps the "neat" way is to factor the common code out to a separate > function, and call that one from several locations. > > > Bo Persson > > But there is the lovely code (Tom Duff's (May 7, 1984) method for fast copying) which should be kept tidied away in a function and with a good comment somewhere.. Bill Davy |
|