Differentiate between a for loop and a while loop? What are it uses?

Showing Answers 1 - 1 of 1 Answers

satish_sudi

  • Jun 25th, 2007
 

There are certain criteria need to be fulfill to use the programming loops.
For loop:
   If the size of the elements or limit of the sequences or end condition is known, then we can use for loop.
Ex:
 #define LIMIT=100;
         for(int i=0; i<LIMIT; i++)
              // some operations



While loop:
If the end condition is unknown, then we can use while loop with proper relational conditions.

Ex:
int counter=0;
  while (counter++ <500 /*or any condition */)
     //some operations


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions