0
Explain about switch in c program
1 Respuesta
+ 2
switch is just an alternative to nested if-else to test values:
switch (x) {
case 1:
//do stuff 1
break;
case 2:
//do stuff 2
break;
case 3:
//do stuff 3
break;
default:
//do default stuff
}
is the same as
if (x == 1) {
//do stuff 1
}
else if (x == 2) {
//do stuff 2
}
else if (x == 3) {
//do stuff 3
}
else {
//do default stuff
}