Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control cannot fall through from one case label to another?

Control cannot fall through from one case label to another?

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dec82
    wrote on last edited by
    #1

    i'd like to get my code executed from case 1 to case 3, but i got this error . Here are my codes : int State = 1 switch (State) { case 1: a=1; a++; State++; case 2: State++; case 3: a=0; } Thanks

    L L 2 Replies Last reply
    0
    • D dec82

      i'd like to get my code executed from case 1 to case 3, but i got this error . Here are my codes : int State = 1 switch (State) { case 1: a=1; a++; State++; case 2: State++; case 3: a=0; } Thanks

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      No, you can't fall through from one case/default into another one. You can only break or change the program flow somehow, e.g. return, throw, and goto. IMO goto and label can be acceptable inside a switch. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      1 Reply Last reply
      0
      • D dec82

        i'd like to get my code executed from case 1 to case 3, but i got this error . Here are my codes : int State = 1 switch (State) { case 1: a=1; a++; State++; case 2: State++; case 3: a=0; } Thanks

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can't drop through a case, but you could always include it inside a loop, so each case is executed until the value is outside of the maximum.

        ___________________________________________ .\\axxx (That's an 'M')

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups