# 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:

  1. while loop
  2. do...while loop
  3. 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


  1. Generate following output.
0
1
2
3
4
5
1
2
3
4
5
6
  1. Print your name 10 times , using only one variables

# do-while loop

C also provides a do-while structure:

TASKS


  1. Print your name 10 times , using only one variables
(adsbygoogle = window.adsbygoogle || []).push({});

# 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/
}
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
}
1
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


  1. Print your name 10 times , using only one variables

# Conclusion

In order to repeat statement , we must follow three step :

  1. Initialization
  2. Test Condition
  3. Update(Increment or Decrement)