Loopy wanderer: loops
Repeating actions in code.
We'll cover the following...
We'll cover the following...
Loops
To move the robot in five different directions, you probably had some code like this, repeated five times:
Is there a way to make Java do the same thing over and over again, so that we don’t have to type the same lines of code over and over again? Yes! The next code shows a programming construct called a for-loop that causes Java to execute the lines of code inside the braces of the loop 5 times:
Exercise: loopy wanderer
Write code to make the robot wander randomly for 20 turns.