Home » , , » Loop Control Statement in C Programming - " for loop " 2

Loop Control Statement in C Programming - " for loop " 2

Written By Unknown on Wednesday, October 9, 2013 | 11:36 PM

Nested for loop :
We can use one or more for loops in between one for loop.This is called nested for loops.Sometime it become very very important to use nested for loop.


For loop variations :

We can initialize more than one variable in to for lop.Like :
                                                           for( i=0, j=0; i<20; i++ )
                                                           for( p=1,q=1; p+q<20; p++,q++ )


We can also initialize variables outside of for loop.Like :
                                                           i=0  //initialization
                                                           for( ; i<20; i++ )


If we need to use increment/decrements outside of for loop than we can do like this :
                                                           i=0
                                                           for(;i<20;)
                                                           {
                                                                 printf("%d",i);
                                                                 i++;    //increment
                                                            }


We can use logical operators too in between conditions like :
                                                           j=0;
                                                           for ( i=0; i<10 && j!90; i++ )

Infinite for loop :
If we need to create an infinite loop we can use for.To create this infinite loop we cannot use initialization,condition and increment into for.Like :
                                                            for( ; ; )
                                                            {
                                                                  printf("\n finite loop \n");
                                                             }

After running this program press Ctrl - Break at a time.
Share this article :

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Learn Programming - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger| Distributed by Rocking Templates