How do I rewrite the following into switch statements? Do I have to define those conditions in the if parentheses?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int x = 0;
int i = 1, j = 2, k = 3, m = 4, n = 5;
if (x > 15 && x <= 19) {
i += 1;
} elseif (x == 21) {
j += 2;
n = 8;
} elseif (x > 21 && x < 23) {
k *= 3;
} else {
m += k + 5;
}
Hi, jonnin. Sorry, beginner question: is there a specific reason for adding parentheses around the numbers in ‘case’ statements or is just something to improve readability or similar?