Goto case?

P

Paul N

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.
 
P

paperab

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
 
B

Bo Persson

Paul said:
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
 
M

Mick

Paul said:
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 )
()~*~()
(_)-(_)
 
B

Bill Davy

Bo Persson said:
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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top