Guide to Object-oriented Programming With Java (Buffalo State University Version)
Chapter 9: Using Loops
Java provides a few different control structures that allow you to loop through data using a set of statements.
The Java for
Loop
The for
statement provides a way to loop through a statement, or group of statements, a number of times.
The Java for
Loop With an Array
The for
loop statement also provides a way to "walk" through an array.
The Java while
Loop
The while
loop statement provides a way to to perform a statement or statements based on a condition being true or false.
The Java do / while
Loop
The do ... while
loop statements provide a way to to perform a statement or statements based on a condition being true or false. A do ... while
loop tests the condition at the end of the loop. S, a do ... while
loop will always execute at least once.
Let's get started with a While program!