This 11-video course examines the use of loops in Java, where iterative control structures are named for-loops, while loops, and do-while loops. This course opens by studying simple for-loops and introduces the concepts of the check expression, the loop variable, and the UPDATE statement. You will learn how to use enhanced for-loops, popular for iterating over arrays and collections. Participants then explore how to short-circuit a loop by using the break statement, and how to short-circuit the current iteration by using continue. Once a break statement is encountered in a loop, it is automatically terminated and the program control resumes at the next statement following the loop. The course then demonstrates how to do this in the context of for-loops, while loops, and do-while loops. You will learn to identify situations where for-loops are preferable to while loops. Finally, examine the dangers of infinite looping in the context of while looping, and learn to identify common pitfalls that lead to infinite looping and how to avoid these pitfalls.
use for loops to iteratively execute a block of code
prematurely terminate loop execution using the break keyword
short-circuit execution of the current loop iteration using the continue keyword
effectively use nested loops
use enhanced for loops, also known as for-each loops, to iterate over arrays and iterable objects in Java
use while loops to control the number of times a block of code executes based on the value of a specific expression
use multiple loop variables to control the number of iterations in a while loop
identify common causes of infinite looping, such as incorrect use of the continue keyword
use the do-while loop control structure to ensure that the body of a loop is always executed at least once, regardless of the value of the loop variable