This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Switch Case Statement problem

I am using switch statement as follows

uint16 val;

switch (val)
{ case 0x0000:
...
break
case 0x0001:
...
break
case 0x0000:
...
break
case 0x0000:
...
break
case 0x0000:
...
break
case 0x0004:
...
break
case 0x0005:
...
break
case 0x0304:
break;

default:
break
}

some times control jumps from one case to other case eventhough there are break statements for each case.

Thanks
Pankaj

Parents
  • I am sorry there is correction in this piece of code
    I missed values, I wanted to show the sample code as the actual code is quite big.

    uint16 val;

    switch (val)
    { case 0x0001:
    ...
    break;
    case 0x0010:
    ...
    break;
    case 0x0020:
    ...
    break;
    case 0x0030:
    ...
    break;
    case 0x0100:
    ...
    break;
    case 0x0004:
    ...
    break;
    case 0x0205:
    ...
    break;
    case 0x0304:
    break;

    default:
    break;
    }

    What happens when I execute this and debug it then control goes to one case and then jumps to the another case though each case has a break, syntax and all are correct, no compile time errors.

Reply
  • I am sorry there is correction in this piece of code
    I missed values, I wanted to show the sample code as the actual code is quite big.

    uint16 val;

    switch (val)
    { case 0x0001:
    ...
    break;
    case 0x0010:
    ...
    break;
    case 0x0020:
    ...
    break;
    case 0x0030:
    ...
    break;
    case 0x0100:
    ...
    break;
    case 0x0004:
    ...
    break;
    case 0x0205:
    ...
    break;
    case 0x0304:
    break;

    default:
    break;
    }

    What happens when I execute this and debug it then control goes to one case and then jumps to the another case though each case has a break, syntax and all are correct, no compile time errors.

Children