View unanswered posts | View active topics It is currently Fri Aug 01, 2014 10:45 am






Reply to topic  [ 9 posts ] 
goto command 
Author Message
Rookie

Joined: Tue Jul 26, 2011 11:07 am
Posts: 3
Post goto command
I notice there is a goto command in robotc, but I am not sure of the correct usage of it. What I want to do is skip to a certain line of code if a condition is met. Is that a possibility?


Tue Jul 26, 2011 12:35 pm
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 403
Post Re: goto command
Hi benroth,

You could use a goto (which is generally not considered good programming practice), but an if-else statement would probably be a much better method: http://www.education.rec.ri.cmu.edu/pro ... f_else.pdf

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Tue Jul 26, 2011 12:52 pm
Profile
Rookie

Joined: Tue Jul 26, 2011 11:07 am
Posts: 3
Post Re: goto command
Thanks. If I were to practice poor programming and use the goto, how would I do that? Do I need parentheses? How do I point it to the line number? etc.

I found out I could probably do a StopTask, but I can't get that to work either. I put that in according to the help file and it doesn't work. My task is named "third" I put in the following code:

StopTask(third);

I get the error "possible invalid reference to procedure 'third'"


Tue Jul 26, 2011 3:11 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: goto command
Code:
void myfunc()
{
    if (Condition1) goto SkipTheRest;
    //
    // Do some stuff here.
    //
SkipTheRest:
    return;
}


Tue Jul 26, 2011 7:52 pm
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 403
Post Re: goto command
Hi benroth_r,

I think I've been responding to your questions here, and on the PLTW forums. Before you try out multitasking, I recommend giving this page a look: viewtopic.php?f=11&t=3341

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Wed Jul 27, 2011 9:16 am
Profile
Rookie

Joined: Tue Jul 26, 2011 11:07 am
Posts: 3
Post Re: goto command
Thanks everyone. I did get around using the goto. I have been using task and function interchangeably. I see there is a difference. Thanks again for all your help.


Wed Jul 27, 2011 11:14 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3168
Location: Rotterdam, The Netherlands
Post Re: goto command
The programming world thanks you for not resorting to gotos. They are the work of the devil and should be avoided like the plague.

goto == bad!

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jul 29, 2011 1:21 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: goto command
I'm sorry, but I couldn't resist:
Image
http://xkcd.com/292/

_________________
sudo rm -rf /


Fri Jul 29, 2011 11:48 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3168
Location: Rotterdam, The Netherlands
Post Re: goto command
Yes, raptors will come and kill you if you use goto. True story!

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jul 29, 2011 12:01 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.