Probably a basic question but I would like to reduce some code using multiple arguments on switch case statements. Possible? Correct syntax?
switch (myInteger){
case (1): //here I would like to apply multiple arguments as case (1 || 3 || 5)
<#statements#>
break;
case (2):
<#statements#>
break;
default:
break;
You can use multiple case
s right below each other.
switch (myInteger) {
case 1:
case 3:
case 5:
// statements
break;
case 2:
// statements
break;
default:
// statements
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With