You are on page 1of 1

//2.

8 For loop
Java for loop used to repeat execution of statement(s) until a certain condition
holds true.
The general form of the for statement can be expressed as follows:

for (initialization; termination; increment)


{
statement(s)...
}

You can initialize multiple variables, test many conditions and perform increments
or decrements on many variables according to requirement.
All three components of for loop are optional.

For example, to execute a statement 5 times:


for (i = 0; i < 5; i++)
statements...;

Another way of doing this is:i = 4;


while (i>=0)
statements...;

You might also like