Finite Loops

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

Finite Loops

Postby sweg » Thu Aug 16, 2012 11:40 pm

Maybe an easy question... I'm very new to writing code for the NXT and can't seem to find it online or any examples in the book I have that contains LeJOS programming examples...

Anyways, is there a way to program a robot to run a loop specific number of times?
Something like the below to get it to run a string of commands some number of times.

Code: Select all
while( x = x+1 < 4 true) {
}
sweg
New User
 
Posts: 2
Joined: Thu Aug 16, 2012 11:32 pm

Re: Finite Loops

Postby skoehler » Fri Aug 17, 2012 3:45 am

Use a for-loop:
Code: Select all
for (int x=0; x<4; x++) {
  // this is executed 4 times
}


If possible, get a good Java book from your local library. leJOS doesn't have its own programming language. You write your programs in ordinary Java.
skoehler
leJOS Team Member
 
Posts: 1110
Joined: Thu Oct 30, 2008 4:54 pm

Re: Finite Loops

Postby sweg » Fri Aug 17, 2012 4:32 am

Ahh, I was thinking about getting some java books, but wasn't sure how close leJOS actualy was. Thanks! :)
sweg
New User
 
Posts: 2
Joined: Thu Aug 16, 2012 11:32 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff