What is the similarity between 'if' statement ans 'switch' statement?

1 answer

Answer

1281747

2026-05-14 12:55

+ Follow

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.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.