Search code snippets, questions, articles...

Switch with connected cases

Switch with multiple connected cases with the same return value
switch (this) {
    case WeatherState.clear:
        return WeatherCondition.clear;
    case WeatherState.snow:
    case WeatherState.sleet:
    case WeatherState.hail:
        return WeatherCondition.snowy;
    case WeatherState.thunderstorm:
    case WeatherState.heavyRain:
    case WeatherState.lightRain:
    case WeatherState.showers:
        return WeatherCondition.rainy;
    case WeatherState.heavyCloud:
    case WeatherState.lightCloud:
        return WeatherCondition.cloudy;
    default:
        return WeatherCondition.unknown;
}

Search Index Data (The code snippet can also be found with below search text)

switch
case
multiple
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet