Difference between revisions of "While"
From SDU
Agegeleruvy (Talk | contribs) |
m (Reverted edits by Agegeleruvy (Talk); changed back to last version by FrankTR) |
||
| Line 1: | Line 1: | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
__NOTOC__ | __NOTOC__ | ||
[[Category:r6]] | [[Category:r6]] | ||
| Line 15: | Line 7: | ||
== Overview == | == Overview == | ||
| − | A | + | A "while" loop performs a set of commands for each iteration of the loop. |
== Usage == | == Usage == | ||
| Line 25: | Line 17: | ||
i = 0; | i = 0; | ||
| − | while( i | + | while( i < 10 ) { |
| − | printf( | + | printf("This is a test. Loop %s\n", i) ; |
i = i + 1; | i = i + 1; | ||
| Line 33: | Line 25: | ||
} ; | } ; | ||
| − | This example will iterate the loop, printing the | + | This example will iterate the loop, printing the "This is a test. Loop n" message 9 times. |
== Results == | == Results == | ||
| − | This is a test. Loop 0 | + | This is a test. Loop 0<BR> |
| − | This is a test. Loop 1 | + | This is a test. Loop 1<BR> |
| − | This is a test. Loop 2 | + | This is a test. Loop 2<BR> |
| − | This is a test. Loop 3 | + | This is a test. Loop 3<BR> |
| − | This is a test. Loop 4 | + | This is a test. Loop 4<BR> |
| − | This is a test. Loop 5 | + | This is a test. Loop 5<BR> |
| − | This is a test. Loop 6 | + | This is a test. Loop 6<BR> |
| − | This is a test. Loop 7 | + | This is a test. Loop 7<BR> |
| − | This is a test. Loop 8 | + | This is a test. Loop 8<BR> |
| − | This is a test. Loop 9 | + | This is a test. Loop 9<BR> |
Latest revision as of 05:21, 30 November 2010
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.
To discuss or ask questions about this article, select the discussion tab above.
Overview
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