|
Page 1 of 1
|
[ 4 posts ] |
|
| Author |
Message |
|
Programmer0724
Rookie
Joined: Tue Nov 30, 2010 9:24 pm Posts: 11
|
 Syntax not working
Ok, so ive been writing code for a bit and every little while i can not get an "else" statement to work, ive looked through my previous codes and it is typed the same way. Here are the errors that occur **Error**:Unexpected 'else'. Ignored. **Error**:Unexpected scanner token-> 'if' **Error**:Unexpected scanner token-> '(' **Error**:Missing ';' before ')' **Error**:Unexpected scanner token-> ')' *Warning*:Meaningless statement -- no code generated
My code is as following
#pragma config(Hubs, S1, HTMotor, HTServo, none, none) #pragma config(Sensor, S2, Mag, sensorHiTechnicMagnetic) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop) #pragma config(Servo, srvo_S1_C2_1, , tServoStandard) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{ while(true) { if(SensorValue[Mag] > 800); { servo[servo1] = 255; } else if(SensorValue[Mag] <= 800); { servo[servo1] = 0; } }} any help would be appreciated
|
| Mon Jan 31, 2011 8:45 pm |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Syntax not working
You code should look more like this:  |  |  |  | Code: #pragma config(Hubs, S1, HTMotor, HTServo, none, none) #pragma config(Sensor, S2, Mag, sensorHiTechnicMagnetic) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop) #pragma config(Servo, srvo_S1_C2_1, , tServoStandard) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { while(true) { if(SensorValue[Mag] > 800) { servo[servo1] = 255; } else if(SensorValue[Mag] <= 800) { servo[servo1] = 0; } } }
|  |  |  |  |
You have extra ';' at the end of the if statements.
|
| Mon Jan 31, 2011 9:42 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 495
|
 Re: Syntax not working
I have seen several people do this recently: As MHTS said, you should be doing this: Since other people have been making the same mistake, I'm curious as to whether you saw an incorrect example. Where did you learn the if statement syntax?
_________________ sudo rm -rf /
|
| Mon Jan 31, 2011 10:00 pm |
|
 |
|
Programmer0724
Rookie
Joined: Tue Nov 30, 2010 9:24 pm Posts: 11
|
 Re: Syntax not working
Yeah, figured that out haha, its always the simplest mistakes, thanks for the help 
|
| Tue Feb 01, 2011 4:44 pm |
|
|
|
Page 1 of 1
|
[ 4 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 5 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|