switch
statement having only a default
case is redundant CS-R1124A switch
statement allows you to handle various cases for a given input. The default
case is executed when none of the specified cases match the given input and can be considered as a fallback case. However, a switch
statement with just a default
case effectively achieves nothing and should be refactored by adding more cases or by using an alternate flow statement such as an if
statement.
switch (i)
{
default:
// ...
break;
}
switch (i)
{
case 0:
// ...
break;
case 1:
// ...
break;
default:
// ...
break;
}