switch (expr) { case c1: statements // do these if expr == c1 break; case c2: statements // do these if expr == c2 break; case c2: // multiple values can share same statements case c3: case c4: statements // do these if expr == any of c2, c3, or c4 break; default: statements // do these if expr != any above }
if
statementif (expr==c1) { statements } else if (expr==c2) { statements } else if (expr==c2 || expr==c3 || expr==c4) { statements } else { statements }
The unusual situation of one case falling into another without a break statement can not be as easily translated into an if statement; either extra tests or the forbidden goto must be used.