C Decision Making - Looping

For loop description

The body of the loop is entered only if the test condition is satisfied and after the completion of the execution of the loop the control is transferred back to the increment part of the loop.
The control variable is incremented using an assignment statement such as I=I+1 or simply I++ and the new value of the control variable is again tested to check whether it satisfies the loop condition.
If the value of the control variable satisfies then the body of the loop is again executed. The process goes on till the control variable fails to satisfy the condition.

Additional features of for loop

We can include multiple expressions in any of the fields of for loop provided that we separate such expressions by commas. For example in the for statement that begins
For( I = 0; j = 0; I < 10, j=j-10)
Sets up two index variables I and j the former initialized to zero and the latter to 100 before the loop begins. Each time after the body of the loop is executed, the value of I will be incremented by 1 while the value of j is decremented by 10.

Just as the need may arise to include more than one expression in a particular field of the for statement.
For(j=0;j!=100;++j)
The above statement might be used if j were already set to some initial value before the loop was entered. A for loop that has its looping condition field omitted effectively sets up an infinite loop, that is a loop that theoretically will be executed for ever.

Sample program (FOR LOOP)

#include < stdio.h > //Include stdio.h file 
void main() //start main program 
{ 
     int I; //declare variable 
	 i=0; //initialize variable. 
	 for(I=0;I < 5; I++) //for loop 
	 { 
        printf(“I%d”,i);
	} //end of for loop 
}
        

Make Comments..!!


Oops!! No posts from user.

Download Android App