Looping Constructs
Looping constructs are used to perform a certain operation a given number of times as long as a condition is being met. They are commonly used to perform a specific operation on the items of a list. An example is when we want to find the summation of all the numbers from 1 to 100. Java supports the following looping constructs:
for loops
for each loops
while loops
do while loops
for Loops
The syntax of the for loop is as follows:
for( initialization ; condition ; expression) { //statements }
The initialization statements are executed when the for loop starts executing. It can be more than one expression, all separated by commas. The expressions must all be of the same type:
for( int i = 0, j = 0; i <= 9; i++)
The condition section of the for loop must evaluate to true or false. If there is no expression, the condition defaults to true.
The expression part is executed after each iteration of the statements, as long as the condition is true. You can have more than one expression...