Goto case?

Discussion in 'C++' started by Paul N, Nov 2, 2009.

  1. Paul N

    Paul N Guest

    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, Nov 2, 2009
    #1
    1. Advertising

  2. Paul N

    paperab Guest

    On Nov 2, 10:33 pm, 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.


    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, Nov 3, 2009
    #2
    1. Advertising

  3. Paul N

    Bo Persson Guest

    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, Nov 3, 2009
    #3
  4. Paul N

    Mick Guest

    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, Nov 3, 2009
    #4
  5. Paul N

    Bill Davy Guest

    "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, Nov 4, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks
    Replies:
    2
    Views:
    1,261
    Steve Franks
    Jun 10, 2004
  2. Replies:
    2
    Views:
    411
  3. Replies:
    10
    Views:
    537
    Flash Gordon
    Aug 15, 2007
  4. siddhant3s

    Re: Goto case?

    siddhant3s, Nov 2, 2009, in forum: C++
    Replies:
    0
    Views:
    394
    siddhant3s
    Nov 2, 2009
  5. Replies:
    31
    Views:
    233
    Tim Rentsch
    Apr 15, 2014
Loading...

Share This Page