1 | | == Loops |
2 | | It's also important for a program to be able to do things repeatedly; for example, the robot must read its sensors repeatedly and react only when certain conditions are met. Consider (and try running) the following program: |
3 | | {{{ |
4 | | public class LoopExample { |
5 | | public static void main(String args[]) { |
6 | | int counter; |
7 | | |
8 | | counter = 1; |
9 | | while (counter <= 10) { |
10 | | System.out.println(counter); |
11 | | counter = counter + 1; |
12 | | } |
13 | | } |
14 | | } |
15 | | }}} |
16 | | * Save this program as !LoopExample.java |
17 | | * Run the program in the debugger with a breakpoint set at the line while (counter <= 10) |
18 | | * Step through the program a line at a time, observing the program output, variables, and flow of execution |
19 | | * There are three types of [https://www.geeksforgeeks.org/loops-in-java/ loops in Java] including while, for, and do loops. Read about them and try a few! |
20 | | |