Control Flow – Looping in C

Looping flow control statements in C programming language execute a specific set of statements multiple times as long as some condition is true. The Looping statements supported by C language include

1. while statement
2. do while statement
3. for statement

In a program written in any programming language it is common to repeat a specific set of statements multiple times. As an example, consider that we want to get a number from user, increment it by 1 and display it. We can accomplish this by using scanf() function that will populate some variable, increment it and then display it using printf(). Now, consider that we have to perform this task 10 times. What should we do? Till now the only way we can achieve this is to write these statements 10 times. Or another way can be to execute the program 10 times. Well 10 is a very small number as compared to 10,000 or so. You can argue that doing copy paste can solve this. Indeed, yes.

Let us modify the above program to display multiplication table of any number entered by user. In this case, we will get some number from user using scanf(), multiply it by 1, and display the result using printf(). Then, multiply the same number by 2 and display the result. The procedure needs to be repeated while the number is not multiplied by 10. You can see that we are repeating a specific set of statements 10 times. These statements include multiplying by an integer and displaying the result. This task can be achieved easily and efficiently by using Looping statements in C language.