What is loop in C Programming Language ?

what is loop in c

In this article we will be going to discuss about loop in C language in which following topic are included:
  • What is loop in C ?
  • Entry-controlled loop
  • Exit-Control loop
  • Sentinel Loops
  • Types of loop in C

What is loop in C ?

In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop therefore consists of two segments, one know as the body of the loop and other know as the control statement 

The control statement tests certain condition and then directs the repeated execution of the statements contained in the body of the loop.

Depending on the position of the control statement in the loop, a control structure may be classified as the entry-controlled loop, or as the exit-controlled loop. 

In the entry-controlled loop, the control conditions are are tested before the start of the loop execution. If the condition is not satisfied, then the body of the loop is not executed.

In the case of exit-controlled loop, the test is performed at he end of the body of the loop and therefore the body executed unconditionally for the first time. The entry-controlled loop and exit-control loop are also know as pre test and post test loops in C respectively.

Sentinel Loops

Based on nature of control variable and the kind of value assigned to it for testing the control expression , the loop is classified into following two general categories
  1. Counter-controlled loop
  2. Sentinel-controlled loop
The counter-controlled loop is sometime is called definite repetition loop because when we know in advance how many times loop will executed their we use counter controlled loop.

In a sentinel-controlled loop, a special value is called a sentinel value is used to change the loop control from true to false.

Types of loop in C

The C language provides for three construct for performing loop operations. They are:
  1. The for loop (for statement)
  2. The while loop (while statement)
  3. The do_while loop ( do statement)
These loop are discussed in next article in detail show if you want read then goto bottom of this article there you will get the link of these three loops.

Example of loop in C

#inc1ude<stdio.h>
main ( )
(
int i=l;
while(i.::=10)
{
printf("%d\t",i) ;
i=i+1;                       / * Statement that changes the value of condition * /
}
printf(~'\n") ;
return 0;
}

Conclusion

In this article we have learnt about loops in C language in details in further article we will learn about its types like for,while and do while , if you have any queries in this article then
feel free comment below.

___________________________________________

Post a Comment (0)
Previous Post Next Post