ROBOTC.net forums
http://www.robotc.net/forums/

goto command
http://www.robotc.net/forums/viewtopic.php?f=11&t=3395
Page 1 of 1

Author:  benroth_r [ Tue Jul 26, 2011 12:35 pm ]
Post subject:  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?

Author:  jbflot [ Tue Jul 26, 2011 12:52 pm ]
Post subject:  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

Author:  benroth_r [ Tue Jul 26, 2011 3:11 pm ]
Post subject:  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'"

Author:  MHTS [ Tue Jul 26, 2011 7:52 pm ]
Post subject:  Re: goto command

Code:
void myfunc()
{
    if (Condition1) goto SkipTheRest;
    //
    // Do some stuff here.
    //
SkipTheRest:
    return;
}

Author:  jbflot [ Wed Jul 27, 2011 9:16 am ]
Post subject:  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

Author:  benroth_r [ Wed Jul 27, 2011 11:14 am ]
Post subject:  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.

Author:  mightor [ Fri Jul 29, 2011 1:21 am ]
Post subject:  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

Author:  magicode [ Fri Jul 29, 2011 11:48 am ]
Post subject:  Re: goto command

I'm sorry, but I couldn't resist:
Image
http://xkcd.com/292/

Author:  mightor [ Fri Jul 29, 2011 12:01 pm ]
Post subject:  Re: goto command

Yes, raptors will come and kill you if you use goto. True story!

- Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/