Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Practical C Programming, 3rd Edition    (ISBN: 1565923065)


 

 List Price: $34.95
 Our Price: $24.47
 Used Price: $7.73

 Release Date: August, 1997
 Manufacturer: O'Reilly & Associates (Paperback)
 Sales Rank: 53,221

 Author: Steve Oualline









More Info

 While Loop 2002-01-05 19:10:38
 
Category: source:c:general
Description: Example of a while loop
Platform: unix/win
Author: mind
Viewed: 5741
Rating: 2.4/5 (19 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
while.c
/* while.c by mindsport [mind@infract.net]
 *
 * example on a while() loop
 *
 * 01/05/02
 *
 */


#include <stdio.h>

int main() {
  int count = 0; /* declare count as an integer of 0 */
  int max = 10; /* declare max as an integer of 10 */
  char msg[]="Test!!\n"; /* define msg as a string with text 'test' */

  while(count < max) { /* loop the below statement until count = or > max */
    fprintf(stderr, "%i: %s", count, msg); /* foreach loop print the results */
    count++; /* increase count by 1 */
  }

  /* ++ is used to increase an integers size, -- is used to decrease an
   * integers size.. for a more realistic count change 0 to 1 */

  /* for an endless while statement use while(1) { }
   *
   * while(1) {
   *   fprintf(stderr, "test-> ");
   * }
   *
   * exit() to break a while statement */
}
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?