# C Looping Make computer repeat task for you
Likewise in real world , we must repeat task in order to meet certain requirement .There are three loops in C programming:
- while loop
- do...while loop
- for loop
# WHILE LOOP
You’ll find that while statements are just as easy to use as if statements. For
This causes the two lines within the braces to be executed repeatedly until a is greater than or equal to b. The while statement in general works as illustrated to the right.
TASKS
- Generate following output.
0
1
2
3
4
5
2
3
4
5
6
- Print your name 10 times , using only one variables
# do-while loop
C also provides a do-while structure:
TASKS
- Print your name 10 times , using only one variables
# for loop
The for loop in C is simply a shorthand way of expressing a while statement. For example, suppose you have the following code in C:
x = 1;
while ( x < 10)
{
blah blah blah
x ++; / ∗ x++ is the same as saying x = x+1 ∗ /
}
2
3
4
5
6
You can convert this into a for loop as follows:
for ( x = 1 ; x < 10 ; x ++)
{
blah blah blah
}
2
3
4
Note that the while loop contains an initialization step (x=1), a test step (x<10), and an increment step (x++). The for loop lets you put all three parts onto one line
TASKS
- Print your name 10 times , using only one variables
# Conclusion
In order to repeat statement , we must follow three step :
- Initialization
- Test Condition
- Update(Increment or Decrement)