A Switch statement can be considered as a series of if. else if. else statements. whatever condition is satisfied, the code block would get executed.
if (cond 1) {
} else if (cond 2) {
} else if (cond 3) {
} ......
} else if (cond N) {
} else {
}
switch {
case 1: ....
case 2: ....
....
case N: ...
default: ...
}
Difference:
In the if else blocks, if one condition is satisfied, all other blocks are ignored
In Switch blocks, unless you have break statements inside each condition block, the subsequent blocks would not be ignored.
Copyright © 2026 eLLeNow.com All Rights Reserved.