Sometimes it is necessary for the program to execute the statement several times. A loop executes a block of commands a specified number of times until a condition is met. In this tutorial, you will learn about all the looping statements of C programming along with their use.
What Is Loop?
A computer is the most suitable machine for performing repetitive tasks, and it can perform a task thousands of times. Every programming language has the feature to instruct to do such repetitive tasks with the help of certain statements. The process of repeatedly executing a collection of statements is called looping. The statements get executed many numbers of times based on the condition. But if the condition is given in such logic that the repetition continues any number of times with no fixed condition to stop looping those statements, then this type of looping is called infinite looping.
All are slightly different and provide loops for different situations.
Figure - Flowchart of Looping:
C Loop Control Statements
Loop control statements are used to change the normal sequence of execution of the loop.
|break statement||break;||It is used to terminate loop or switch statements.|
|continue statement||continue;||It is used to suspend the current loop iteration and transfer control to the loop for the next iteration.|
|goto statement||goto labelName;
|It transfers the current program execution sequence to some other part of the program.|