In C programming language, a loop is a sequence of instruction s that is executed repeatedly until a certain condition is satisfied. Mostly, a specific process is done, such as getting data and changing it, and then some prescribed condition is checked such as whether a counter has reached a prescribed number. Here in this C programming tutorial we use almost all types of loops in our programs.
Below flowchart describes the working of a typical loop in C programming.
C programming language provides the following types of loop to handle looping requirements.
WHILE LOOP IN C
while a given condition is true, a statement or group of statements is executed continuously in c language. Initial condition is always checked before executing the loop body as shown below.
FOR LOOP IN C LANGUAGE
A variable which is initialized to a prescribed value is compared with a condition, if true then body of the loop is executed and variable is incremented the loop will continue to go no until it reached the prescribed value. for loop structure is like initialization, condition and finally increment. For loop is one of the best used loop in C programming.
DO WHILE LOOP IN C PROGRAMMING LANGUAGE
In C language, do while loop, the condition is checked after executing the loop body. It is just like the while loop the difference is condition is checked only at end, as it is called as exit controlled loop.
NESTED LOOPS IN C
In nested loops, a loop is used with in another loop which makes a nested structure of loops in C language, C programming language provides this capabilities.
BREAK STATEMENT IN C PROGRAM
If test condition returns true, Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. Break is used to exit a loop in C language.
CONTINUE STATEMENT IN C LANGUAGE
Causes the loop to jump over the remaining portion of its body and immediately retest its condition prior to reiterating.
GOTO STATEMENT IN C PROGRAMMING
Jumps over and Transfers control to the labeled statement. Due to compiler issues it is not recommended to use these statements
0 comments:
Post a Comment