Difference between revisions of "While"

From SDU
Jump to: navigation, search
m
Line 1: Line 1:
 +
__NOTOC__
 +
<div align='center'><font color="green">To make corrections or additions to this article, select the ''edit'' tab above.<br>
 +
To discuss or ask questions about this article, select the ''discussion'' tab above.</font></div>
 +
 
== Description ==
 
== Description ==
 
A "while" loop performs a set of commands for each iteration of the loop.
 
A "while" loop performs a set of commands for each iteration of the loop.
 +
  
 
== Usage ==
 
== Usage ==
 
while (''condition'')
 
while (''condition'')
  
== Examples ==
 
  
 +
== Examples ==
 
     int i;
 
     int i;
 
      
 
      
Line 20: Line 25:
  
 
This example will iterate the loop, printing the "This is a test. Loop n" message 9 times.
 
This example will iterate the loop, printing the "This is a test. Loop n" message 9 times.
 +
  
 
== Results ==
 
== Results ==
Line 32: Line 38:
 
This is a test. Loop 8<BR>
 
This is a test. Loop 8<BR>
 
This is a test. Loop 9<BR>
 
This is a test. Loop 9<BR>
 
----
 
<div align='center'><font color="green">To make corrections or additions to this article, select the ''edit'' tab above.<br>
 
To discuss or ask questions about this article, select the ''discussion'' tab above.</font></div>
 

Revision as of 21:01, 25 July 2008

To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.

Description

A "while" loop performs a set of commands for each iteration of the loop.


Usage

while (condition)


Examples

   int i;
   
   i = 0;    
   
   while( i < 10 ) {
       
       printf("This is a test. Loop %s\n", i) ;
       
       i = i + 1;
       
   } ;

This example will iterate the loop, printing the "This is a test. Loop n" message 9 times.


Results

This is a test. Loop 0
This is a test. Loop 1
This is a test. Loop 2
This is a test. Loop 3
This is a test. Loop 4
This is a test. Loop 5
This is a test. Loop 6
This is a test. Loop 7
This is a test. Loop 8
This is a test. Loop 9