| Author |
Message |
|
benroth_r
Rookie
Joined: Tue Jul 26, 2011 11:07 am Posts: 3
|
 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 |
|
 |
|
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 385
|
 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
|
| Tue Jul 26, 2011 12:52 pm |
|
 |
|
benroth_r
Rookie
Joined: Tue Jul 26, 2011 11:07 am Posts: 3
|
 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 |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: goto command
|
| Tue Jul 26, 2011 7:52 pm |
|
 |
|
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 385
|
 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
|
| Wed Jul 27, 2011 9:16 am |
|
 |
|
benroth_r
Rookie
Joined: Tue Jul 26, 2011 11:07 am Posts: 3
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 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
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Jul 29, 2011 1:21 am |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: goto command
I'm sorry, but I couldn't resist: http://xkcd.com/292/
_________________ sudo rm -rf /
|
| Fri Jul 29, 2011 11:48 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2906 Location: Rotterdam, The Netherlands
|
 Re: goto command
Yes, raptors will come and kill you if you use goto. True story!
- Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Jul 29, 2011 12:01 pm |
|
|