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?
> 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 C++ program may be containing more than one switch construct. And there is a posiblity to find statements such as 'case 1:' in more than one switch constructs. Hence it if at all this feature was there, it would have been ambiguous for the compiler. I don't see a point in considering a `case #n' as a `label'; just because it terminates with a colon?
In short I would reply your last question with No.
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
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.
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.
> 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..