From the course: Oracle Java Foundations

Unlock this course with a free trial

Join today to access over 24,000 courses taught by industry experts.

Loops

Loops

(upbeat electronic music) - [Joe] In this module, we'll learn about loops and iteration. Previously, we talked about controlling program flow with FLs and switch statements. In addition to making decisions, we can also repeat blocks of statements repeatedly, called iteration. We use loops for this in our computer programs. Loops are used then to loop and repeat a block of statements until an expression is false, as long as the expression is true, the loop keeps executing. For example, reading records from a file. Process reading all records until there are no more, you read the first record, are there more? Yes, read the next one, are there more? Yes, read the next one, are there more? No, stop. For a specific number of times, we can process each element of an array, so with loops, we can run the loop until the expression is false, or we can run the loop a specific number of times, so we could run the loop 10 times, or four times, and when we run the loop, we can use the loop to…

Contents