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 ('case 64:') to another?

Control cannot fall through from one case label ('case 64:') to another?

Scheduled Pinned Locked Moved C#
helpquestion
10 Posts 5 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 got this error, And here is my code . Thanks case 64: if (GetFunction() == true) { if (GetStatus() == false) { FunctionError(); } else { Reset(); goto case 65; } }

    C M 2 Replies Last reply
    0
    • D dec82

      I got this error, And here is my code . Thanks case 64: if (GetFunction() == true) { if (GetStatus() == false) { FunctionError(); } else { Reset(); goto case 65; } }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The goto is inside the brackets. You need a break after the if, or after FunctionError() using goto in a case statement is so ugly. THe C# team are morons for requiring us to do this. I never do it, no matter what.

      Christian Graus Driven to the arms of OSX by Vista.

      D 1 Reply Last reply
      0
      • C Christian Graus

        The goto is inside the brackets. You need a break after the if, or after FunctionError() using goto in a case statement is so ugly. THe C# team are morons for requiring us to do this. I never do it, no matter what.

        Christian Graus Driven to the arms of OSX by Vista.

        D Offline
        D Offline
        dec82
        wrote on last edited by
        #3

        Do you have any recommendations for this case ?

        S 1 Reply Last reply
        0
        • D dec82

          Do you have any recommendations for this case ?

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          How about moving the code inside case 65 into a function and calling that from both places?

          Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

          C 1 Reply Last reply
          0
          • S S Senthil Kumar

            How about moving the code inside case 65 into a function and calling that from both places?

            Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Yes, that's what I would do.

            Christian Graus Driven to the arms of OSX by Vista.

            D 1 Reply Last reply
            0
            • C Christian Graus

              Yes, that's what I would do.

              Christian Graus Driven to the arms of OSX by Vista.

              D Offline
              D Offline
              dec82
              wrote on last edited by
              #6

              because i have like 100 cases like that and i prefer not make a case into a function

              S D C 3 Replies Last reply
              0
              • D dec82

                because i have like 100 cases like that and i prefer not make a case into a function

                S Offline
                S Offline
                S Senthil Kumar
                wrote on last edited by
                #7

                dec82 wrote:

                i prefer not make a case into a function

                May I know why?

                Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

                1 Reply Last reply
                0
                • D dec82

                  because i have like 100 cases like that and i prefer not make a case into a function

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  dec82 wrote:

                  i prefer not make a case into a function

                  :omg: OK, you're really doing it the wrong way then. You're making a single monolithic method that does everything instead of breaking up the code into FAR more manageable, supportable, and extendable pieces. I'm afraid if you were working for me, I'd have to fire you for doing that. No joke... I'd probably have to question the validity of using a Switch with 100 cases in it too. But, I say that without knowing anything about what your app does of its data model. If you were using a switch on an integer value, I'd probably look into using delegates stacked in an array or hashtable to shorten up the code and increase its performance. You know, using the switch value as an index into an array? But, like I said, it's only a thought based on no knowledge of what your code is doing or its requirements.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

                  1 Reply Last reply
                  0
                  • D dec82

                    because i have like 100 cases like that and i prefer not make a case into a function

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Well, if you're determined to write bad code, why are you posting about it here ?

                    Christian Graus Driven to the arms of OSX by Vista.

                    1 Reply Last reply
                    0
                    • D dec82

                      I got this error, And here is my code . Thanks case 64: if (GetFunction() == true) { if (GetStatus() == false) { FunctionError(); } else { Reset(); goto case 65; } }

                      M Offline
                      M Offline
                      Megidolaon
                      wrote on last edited by
                      #10

                      Actually break; cause the switch to exit and continue with the codoe afterwards. Leaving it and not writing anything, but simply adding other case will automatically cause the switch to move on and execute all code until the next break; Thus if you have somethng like this:

                      switch(number)
                      case 1: //do stuff
                      break;

                      case 2: //do stuff or not
                      case 3: // do more stuff
                      break;

                      case 4: //do stuff
                      break;

                      the program will do the exact same for 2 and 3. If you don't want it to do anything different for 2, you might as well leave that case empty, so it immediately goes to the next code before the break;

                      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