ruben91
Junior Member level 3
- Joined
- Nov 17, 2014
- Messages
- 29
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 209
i have done an if statement in my project, it worked fine but quite laggy as it takes time to read, so i planned to change it to switch case statement bt i seem to get error i compiling, pls help me to solve this
here is my code
this is my coverted switch statement
bt i get error in compiling
here is my code
if(distance>=0 && distance<=250)
{
PORTDbits.RD2=1;
}
if(distance>=251 && distance<=500)
{
PORTDbits.RD3=1;
}
if (distance>=501 && distance<=1000)
{
PORTDbits.RD0=1;
}
if(distance>=1001)
{
PORTDbits.RD1=1;
}
this is my coverted switch statement
bt i get error in compiling
switch(distance)
{
case distance>=0 && distance<=250:
PORTDbits.RD1=1;
break;
case distance>=251 && distance<=500:
PORTDbits.RD2=1;
break;
case distance>=501 && distance<=1000:
PORTDbits.RD3=1;
break;
case distance>=1001:
PORTDbits.RD4=1;
break;
}