Control cannot fall through from one case label ('case 64:') to another?
-
I got this error, And here is my code . Thanks case 64: if (GetFunction() == true) { if (GetStatus() == false) { FunctionError(); } else { Reset(); goto case 65; } }
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.
-
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.
-
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
-
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
Yes, that's what I would do.
Christian Graus Driven to the arms of OSX by Vista.
-
Yes, that's what I would do.
Christian Graus Driven to the arms of OSX by Vista.
-
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
-
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 -
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.
-
I got this error, And here is my code . Thanks case 64: if (GetFunction() == true) { if (GetStatus() == false) { FunctionError(); } else { Reset(); goto case 65; } }
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;