[RESOLVED] switch statement confusion
uuh I dunno how to do this but I sure do hope it's possible in C#:(
I have a switch and I want code execution to fall from one case to another if a certain condition isn't met
Code:
switch (something)
{
case 1:
if (val==true)
{
//do stuff;
break;
}
else
{
// go on to other case statements.... but how? it won't compile without break;
}
case 2:
case 3:
}
Re: switch statement confusion
From the VS help topic entitled "switch":
Quote:
Unlike the C++ switch statement, C# does not support an explicit fall through from one case label to another. If you want, you can use goto a switch-case, or goto default.
You can fall through from one case to another only if the first case is empty.
Re: switch statement confusion
ah that sucks :(
arg I don't think I should use goto
thanks for the reply
Re: switch statement confusion
I don't get it.
If you don't use break, your code will just carry one excecuting right?
Surely one can use that logic to go to the next switch if a condition is not met?
Re: switch statement confusion
Quote:
Originally Posted by StrangerInBeijing
I don't get it.
If you don't use break, your code will just carry one excecuting right?
Surely one can use that logic to go to the next switch if a condition is not met?
if you put some code in a case block, and don't use "break" you will get a compile error. It would be nice if you could do it like in C++ though :(
Re: switch statement confusion
You'll have to resort to if statements, evaluating both conditions...
Re: switch statement confusion
Quote:
Originally Posted by mendhak
You'll have to resort to if statements, evaluating both conditions...
REALLY?:D
Re: switch statement confusion
Quote:
Originally Posted by MrPolite
REALLY?:D
Khafesho... aqa-e-mashang