# Switch case statement in MikroC for dsPIC? [closed]

I have three decision digital variable. So I have to make 8 decisions with these digital variables. The problem of mine is in understanding the behaviour of the switch-case statement in MikroC.

Actually I have to made decision as when three digital pin are 0 0 0, 0 0 1, 0 1 0. How to enter the these value for switch case variable?

switch (i) {
case 1: i++;
case 2: i++;
case 3: i++;
}


Here my i is three digital pins, such as 0 1 0. How can I implement this?

• In your example if i=1, you will increment it three times. Is that what you are intending? – Tom Carpenter Sep 22 '17 at 20:14
• In any case, it's not clear what you are trying to do. – Tom Carpenter Sep 22 '17 at 20:14
• MikroC is just a compiler that compiles bog standard ANSI C programs. There is no difference in behaviour from the way a switch-case statement works for any C program. – Tom Carpenter Sep 22 '17 at 20:19
• I don't understand this method of programming. Looks like you have a requirement, then you code some random stuff and then you are trying to understand what you have coded and how it is matching your requirement? – Eugene Sh. Sep 22 '17 at 20:19
• You want to make a decision when your input is 0, 1 or 2, yet your switch statement has cases for 1, 2 and 3. – Steve G Sep 22 '17 at 20:31

Your question is how to enter the case numbers. The answer is to enter them like this:

switch (i) {
case 0x00:   // do something if i == 000
break;
case 0x01:   // do something different if i == 001
break;
case 0x02:  // do something yet again if i == 010
default:   // do nothing (optional)
}


If you don't use the break statements, the code 'falls through' to the next case, which may not be what you want (or maybe it is). You can leave out any case numbers that you don't need. Obviously the code you want to execute goes between the case and break statements.