* for statement :
The for loop is entry controlled loop that provides more concise structure.
The general form of for loop is
for(initialization;test-condition;increment/decrement)
{
body of loop
}
* Flow chart :
The execution of the for loop is as follow
▪️ initialization of the control variable is done first,using assignment statement such a i = 1.
the variable[ i ] is known as loop-control variable.
▪️ the value of the 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 condition is a true,the body of the loop is executed; otherwise loop is terminnated and the execution continues with the statement that immediatly follows the loop.
▪️ when the body of the loop is executed, the control is transferred back to the for statement after evaluating last statement in the loop.
Now the control variable is incremented ordecremented using an assignment statement such as i=i+1 or i=i-1 etc and the new value is again tested to see wheather it satisfies the loop condition.
This process continues till test condition becomes false.
consider the following example :
for(x=1; x<=10, x++)
{
printf("%d",10*x);
}
In above example table of 10 will be displayed.
Good ๐๐
ReplyDeleteNice job
ReplyDelete