View unanswered posts | View active topics It is currently Wed Jul 30, 2014 5:15 pm






Reply to topic  [ 10 posts ] 
Breaking the loop 
Author Message
Rookie

Joined: Fri Apr 26, 2013 11:05 am
Posts: 12
Post 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.


Tue Apr 30, 2013 11:00 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: Breaking the loop
You can use "break;" :)

= 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]


Wed May 01, 2013 1:52 am
Profile WWW
Rookie

Joined: Fri Apr 26, 2013 11:05 am
Posts: 12
Post 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.


Fri May 03, 2013 10:13 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Breaking the loop
Was it an unconditional break(i.e. it is not inside an if(donelinetracking) statement)?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Fri May 03, 2013 11:43 am
Profile
Expert
User avatar

Joined: Fri Nov 02, 2012 12:07 am
Posts: 164
Location: California, USA
Post Re: Breaking the loop
mightor wrote:
You can use "break;" :)

= Xander

I thought that that was only for Switches!

_________________
string Robored = "Awesome"
~~Neil Balch~~


Mon Jun 03, 2013 7:58 pm
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post 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.

_________________
Matt


Mon Jun 03, 2013 9:31 pm
Profile WWW
Expert
User avatar

Joined: Fri Nov 02, 2012 12:07 am
Posts: 164
Location: California, USA
Post Re: Breaking the loop
So it makes the program exit a loop? :oops: :oops:

_________________
string Robored = "Awesome"
~~Neil Balch~~


Mon Jun 03, 2013 9:37 pm
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Breaking the loop
Yes, it can. It just tells the program to jump up a level.

_________________
Matt


Mon Jun 03, 2013 9:40 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post 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?

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Jun 03, 2013 9:40 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post 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.

_________________
Matt


Mon Jun 03, 2013 9:43 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 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:  
cron



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