Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

C++ Switch statement !!

$
0
0

So I recently learned about switch statements so I know that they are used as a replacement for if statements. For example,
if statement-
if (x == 1){do function(a)}
if (x == 2){do function(b)}
...

So, this can be written as-
switch(x){
case 1: do function(a);
case 2: do function(b);
}

But what if the if statement was-
if (x > 0){do function(a)}
else if (x < -10){do function(b)}
else{do function(c)}

How do we write this as a switch statement?


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>