if else to switch statement

How to transform if-else statement to equivalent switch statement? I’m gonna show an example. Take a look at the following if-else statement :

First wrap the if-else inside switch block :

if and all if-else blocks become our case blocks, and else will become default case :

And don’t forget to add break :

All cases are actually boolean (num < 0, num >= 0 && num < 100 and num > 100 are actually returning boolean). One of the case will eventually become true depending on the value of num. So our switch condition should be a boolean (true) so that it will match one of the cases :

Done.