Most real programs contain some construct that loops within the program, performing repetitive actions on a stream of data or a region of memory.
A D V E R T I S E M E N T
There are several ways to loop in C. Two of the most common are the while loop:
while (expression)
{
...block of statements to execute...
}
and the for loop:
for (expression_1; expression_2; expression_3)
{
...block of statements to execute...
}
The do loop also executes a block of code as long as a condition is satisfied. The difference between a "do ...while" loop and a "while {} " loop is that the while loop tests its condition before execution of the contents of the loop begins; the "do" loop tests its condition after it's been executed at least once. As noted above, if the test condition is false as the while loop is entered the block of code is never executed. Since the condition is tested at the bottom of a do loop, its block of code is always executed at least once.
Some people don't like these loops because it is always executed at least once. When i ask them "so what?", they normally reply that the loop executes even if the data is incorrect. Basically because the loop is always executed, it will execute no matter what value or type of data is supposed to be required. The "do ....while" loops syntax is as follows
do
{
block of code
} while (condition is satisfied);
The most interesting and also the most difficult of all the loops is the for loop. The name for is a hangover from earlier days and other languages. It is not altogether appropriate for C's version of for. The name comes from the typical description of a classic for loop:
The C for loop is much more versatile than its BASIC counterpart; it is actually based upon the while construction. A for loop normally has the characteristic feature of controlling one particular variable, called the control variable. That variable is somehow associated with the loop. For example it might be a variable which is used to count "for values from 0 to 10" or whatever. The form of the for loop is:
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
Looping Statement in C,
while loop statement,
for loop statement,
c tutorial,
c syntax,
c array,
values statement,
c examples,
nested statement,
looping tutorial,
return c,
null statement,
c language,
sql statement,
looping array,
statement date,