C Looping
There are three methods for making a loop with C. There is a list of all loop structures in C:
I. While loop
II. Do … While loop
III. For loop
I. While Loop
This statement can be very useful if you don’t have or don’t know number of repetitions because it loops the operations while specified conditions are true.
Structure 1.0 : Via this structure, the condition will be evaluated before the loop begin. If conditions are false then loop will be skipped else operations are executed then the conditions will be evaluated again. If conditions are still true then it will execute the operations again…
There is a simple code example that shows us how to use while loop in C.
Example 1.0 :
Output of Example 1.0 :
II. Do … While Loop
There is a little but important difference between while loop and do…while loop With do…while loop, conditions are tested at the end of the loop. The loop is always executed at least once with this usage.
Structure 2.0:
Example 2.0 :
Output of Example 1.0 :
III. For Loop
The for loop depends on a counter ( that increases or decreases by the same amount each time through the loop ) and loops the operations until the counter reaches a specified value.
Structure 3.0:
Example 3.0:
Output of Example 3.0:
IV. Break and Continue Statements in C Loops
4.1 ) Break Statement
Break statement is used for exiting from the loop that contains the break statement immediately.
Example 4.0
Output of Example 4.0:
Example 4.1
Output of Example 4.1:
As you see in the Example 4.0 and Example 4.1 the loop is broken when the break statement is read.
4.2 ) Continue Statement
Continue statement is used for skipping from the loop that contains the continue statement immediately..
Example 4.2
Output of Example 4.2:

Recently Typed