- The most basic control flow statement supported by the Java programming language is the if-then statement.
 - The switch statement allows for any number of possible execution paths.
 - The do-while statement is similar to the
 whilestatement, but evaluates its expression at the bottom of the loop.- Question: How do you write an infinite loop using the
 forstatement?Answer:
for ( ; ; ) { }- Question: How do you write an infinite loop using the
 whilestatement?Answer:
while (true) { }
- Consider the following code snippet.
 if (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string");
- Exercise: What output do you think the code will produce if
 aNumberis 3?Solution:
second string third string- Exercise: Write a test program containing the previous code snippet; make
 aNumber3. What is the output of the program? Is it what you predicted? Explain why the output is what it is. In other words, what is the control flow for the code snippet?Solution:
NestedIf3 is greater than or equal to 0, so execution progresses to the secondsecond string third stringifstatement. The secondifstatement's test fails because 3 is not equal to 0. Thus, theelseclause executes (since it's attached to the secondifstatement). Thus,second stringis displayed. The finalprintlnis completely outside of anyifstatement, so it always gets executed, and thusthird stringis always displayed.
- Exercise: Using only spaces and line breaks, reformat the code snippet to make the control flow easier to understand.
 Solution:
if (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string");- Exercise: Use braces
 {and}to further clarify the code and reduce the possibility of errors by future maintainers of the code.Solution:
if (aNumber >= 0) { if (aNumber == 0) { System.out.println("first string"); } else { System.out.println("second string"); } } System.out.println("third string");