0
C switch issue...!! Is it broken?
Is it not allowed to have any conditional statement within switch cases in C language? As here: int c,d; c=d=1; switch(c){ case 1: if(d==4){ ...do this } //end of if statement break; //for case 1 ...more cases } //end of switch Result: The statement within IF structure is executed every-time. (I have tried changing conditional expressions) I dont remember having any of such restriction or flaw as i say. The problem is occurring in this SoloLearn iphone app, if that matters.
2 Answers
0
I don't have that problem. Works for me:
[code]
#include <stdio.h>
int main() {
int a, b;
a = 1;
b = 10;
switch (a) {
case 1:
if (b < 20)
printf("A1Ble20\n");
break;
}
return 0;
}
[/code]
Double-check everything for typos, etc. Try running the above code with different b values. If it is an SL bug, you'll know and can report it. It's probably human error on your side. We make typos easily on phone keypads.
0
@nonzyro Ok your code worked after changing values too. Iâll re-check my code for any hidden typo and update here soon