Please enable JavaScript to use CodeHS

CodeHS Glossary


For Loop Java

A for loop lets us repeat code a **fixed number of times**. For example, if we want to move 10 spaces or put down 15 tennis balls, we would use a for loop. If we want to move to the wall, but don’t know how far away the wall is, we would not use a for loop, because we don't know exactly how many times we need to move. A for loop looks like: ``` for(int i = 0; i < 10; i++){ move(); } ``` This calls the move() command 10 times, and does the same thing as writing. ``` move(); move(); move(); move(); move(); move(); move(); move(); move(); move(); ```