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

Breaking the loop
http://www.robotc.net/forums/viewtopic.php?f=1&t=5790
Page 1 of 1

Author:  Korndog [ Tue Apr 30, 2013 11:00 pm ]
Post subject:  Breaking the loop

I am having our students work on a challenge of using the touch sensor first, then the light sensor, to track a line. When the NXT reaches the end of the line, it just rotates in a circle since there is no more line to follow. I understand that it is searching for a difference in colors, but how do I write in a stop command, to break the loop? I followed the curriculum lesson where I set the touch sensor value to ==0, but I want to use that sensor before the light sensor.

Thanks.

Author:  mightor [ Wed May 01, 2013 1:52 am ]
Post subject:  Re: Breaking the loop

You can use "break;" :)

= Xander

Author:  Korndog [ Fri May 03, 2013 10:13 am ]
Post subject:  Re: Breaking the loop

I had the kids put in the "break" command and it stopped the robot from tracking the line at all. I had them insert it after the line tracking was to be complete.

Author:  Coder A [ Fri May 03, 2013 11:43 am ]
Post subject:  Re: Breaking the loop

Was it an unconditional break(i.e. it is not inside an if(donelinetracking) statement)?

Author:  roboRed [ Mon Jun 03, 2013 7:58 pm ]
Post subject:  Re: Breaking the loop

mightor wrote:
You can use "break;" :)

= Xander

I thought that that was only for Switches!

Author:  mattallen37 [ Mon Jun 03, 2013 9:31 pm ]
Post subject:  Re: Breaking the loop

you can use "break;" to break out of pretty much any loop, or switch. It basically makes the program jump "up" a level.

Author:  roboRed [ Mon Jun 03, 2013 9:37 pm ]
Post subject:  Re: Breaking the loop

So it makes the program exit a loop? :oops: :oops:

Author:  mattallen37 [ Mon Jun 03, 2013 9:40 pm ]
Post subject:  Re: Breaking the loop

Yes, it can. It just tells the program to jump up a level.

Author:  Ernest3.14 [ Mon Jun 03, 2013 9:40 pm ]
Post subject:  Re: Breaking the loop

Or, use a `while (isCondition)`, set a flag when it reaches the end of the line, if you need to break out of (many) nested loops.
And by "jump up a level", you mean out of the `if()` statement and then another level, right?

Author:  mattallen37 [ Mon Jun 03, 2013 9:43 pm ]
Post subject:  Re: Breaking the loop

Yes, out of the if, and out of the loop the if is in.

Just play around with "break;" to see it in action.

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