I'm new to arduino and can't understand how best to use loops.
I can make different loops:
But when I run the program it runs forward once, then backward once and repeats it over and over again.
I would like it to keep doing forward until a button is pressed, how should i program it?
Are not loops, they are functions that are called from within the main loop that are in all Arduino programs.
So you need to write some code inside Void Loop that reads the state of the button and depending on whetre it is pressed or not calls the forward function.
You should read the Arduino reference to become familiar with the different programming constructs available.
Build your program in little chunks (just like you already have done with forward / backward) and when each little chunk works expand with the next part.
So in your case, first read up on how to hook up a button and read it's state, then go on with calling your forward function.
there are examples in the playground for reading a button.
Also check Lady Ada's Arduino tutorials, they are really good, and also has info on reading and reacting to button presses.
Maybe you could use some of that logic.
Thank you AlphaBeta and MikMo,
That was really useful, I now have a better idea of how to program my arduino[timestamp=1240163615]