How would I make this loop like this one run for a certain amount of time. I heard that I should use the while function, but how would I incorporate it into this code
I'm afraid that from reading your question and your code is is obvious that you do not understand the basics of C/C++.
Please work through the examples in the Arduino IDE, in this forum and elsewhere so you understand better. I found this site (there are plenty of others) helpful when I was learning C C programming
Feel free to come back and ask questions when you don't understand something.
Maybe for you the easiest would be to buy a timer however it is a lot better to take the route you are trying, it will take some time as you have a new language to learn and a different thought process. I would suggest you get a copy of the Arduino Cookbook, read it and do some on line tutorials. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
dla:
How would I make this loop like this one run for a certain amount of time. I heard that I should use the while function, but how would I incorporate it into this code
Not the right way to go about things in the arduino world. The better way is to learn to use millis().
PaulMurrayCbr:
The better way is to learn to use millis().
But also, since "foward()" (which wasn't included in the code) is likely to set some pins high and low to turn a motor on in a certain direction, just no longer calling foward() after 10 seconds isn't going to stop the motor. The pins won't magically go to whatever they need for the next activity, and you're likely to need to call say "stop()" to set the pins all low or whatever, when the time's up.