View unanswered posts | View active topics It is currently Fri Oct 31, 2014 12:23 am






Reply to topic  [ 4 posts ] 
Syntax not working 
Author Message
Rookie

Joined: Tue Nov 30, 2010 9:24 pm
Posts: 11
Post 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
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Syntax not working
I have seen several people do this recently:
Code:
if(statement);
{
//code
}


As MHTS said, you should be doing this:
Code:
if(statement){
//code
}


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
Profile
Rookie

Joined: Tue Nov 30, 2010 9:24 pm
Posts: 11
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.