Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue case in switch

I have following code:

switch(true)
    {
    case (something):
        {
        break;
        }
    case (something2):
        {
        break;
        }
    case (something3):
        {
        break;
        }
    }

Also the switch statement must check what one of cases give a TRUE, that is not the problem, the problem is, that i have now a case, where inside of case ... break; after checking other data, i wish to choose other switch-case, the one, that following him. I have try do this:

switch(true)
    {
    case (something):
        {
        break;
        }
    case (something2):
        {
        if(check)
            {
            something3 = true;
            continue;
            }
        break;
        }
    case (something3):
        {
        break;
        }
    }

But PHP do not wish to go in to the case (something3): its break the full switch statement. How i can pass the rest of code of one case and jump to the next?

like image 281
BASILIO Avatar asked Mar 02 '26 15:03

BASILIO


1 Answers

This is what's called a "fall-through". Try organizing your code with this concept.

switch (foo) {
  // fall case 1 through 2
  case 1:
  case 2:
    // something runs for case 1 and 2
    break;
  case 3:
    // something runs for case 3
    break;
}
like image 114
elclanrs Avatar answered Mar 05 '26 05:03

elclanrs