For Loop

The for loop is another entry-controlled loop that provides a more concise loop structure.The for loop is the easiest to understand of the java loops.The Syntax of the for loop statement is:

 

for( initialization expression(s); test condition; update expression)

{

   loop-body;

}

The execution of the for  statement is as follows:

1.)Initialization of the control  variables is done first,using assignment statements such as i=1 and count=0.The variables are known as loop-control variables.

2.) the value of the control variable is tested using the test-condition.The test condition is a relational expression,such as  i<10 that determines  when the loop will exit.If the condition is true,the body of the loop is executed ,otherwise the loop is terminated and the execution continues with the statement that immediately follows the loop.

3.)When the body of the loop is executed,the control is transferred back to the for statement after evaluating the last statement such as i=i+1 and the new value of the control variable is again  tested to see whether it satisfies the loop condition.if the condition is satisfied,the body of the loop is again executed.This process continues till the value of the control variable fails to satisfy the test condition

This can be understood by the following figure:-

 

   

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s