Adsense 728 * 15

Search

Custom Search

While Loop and it's syntax



What is while loop 



While loop is generally used when we don't how many times a loop must run. It allows code to be executed repeatedly based on some given condition.




Syntax of while loop-


while ( condition ) 



//body of while loop 





For example-


#include <iostream.h>


void main()

  int x = 0;  
  
  while ( x < 5 ) // Condition is the value of x is less than 5



      cout<<x;


      x++;            
  }
  
}


This loop run successfully until the value of x is greater than 4.


Output -
0
1
2
3
4




For loop

No comments:

Post a Comment