You are on page 1of 9

Loop control statements in C are used to perform looping operations until the given condition is true.

Control comes out of the loop statements once condition becomes false. Types of loop control statements: There are 3 types of loop control statements in C language. They are, 1. 2. 3. for while do-while Synta for each C loop control statements are given in below table with description. S.no Loop Name Syntax Description &here, e p1 ' variable initiali(ation ! ) ample* i+,, -+2, .+3 # e p2 ' condition chec.ing ! ) ample* i/0, -13, .+3 # e p3 ' increment2decrement ! ) ample* 33i, -', 33. # where, condition might be a/0, i11, where, condition might be a/0, i11,

for

for !e p1" e p2" e pr3# $ statements" %

2 3

while do while

while !condition# $ statements" % do $ statements" % while !condition#"

Example program (for loop):


4n for loop control statement, loop is e ecuted until condition becomes false .

5include 1stdio.h/ int main!# $ int i" for!i+,"i11,"i33# $ printf!67d 6,i#" % %

Output:
,123809:;<

) ample program !while loop#*


4n while loop control statement, loop is e ecuted until condition becomes false.

5include 1stdio.h/ int main!# $ int i+3" while!i11,# $ printf!67d=n6,i#" i33" % %

Output:
3809:;<

) ample program !do while loop#*

4n do..while loop control statement, while loop is e ecuted irrespective of the condition for first time. Then 2nd time onwards, loop is e ecuted until condition becomes false.

5include 1stdio.h/ int main!# $ int i+1" do $ printf!6>alue of i is 7d=n6,i#" i33" %while!i1+8 ?? i/+2#" %

Output:
>alue of i is 1 >alue of i is 2 >alue of i is 3 >alue of i is 8

Difference bet een !ile " #o !ile loops in C:


S.no !ile @oop is e ecuted only when condition is true. #o !ile @oop is e ecuted for first time irrespective of the condition. After e ecuting while loop for first time, then condition is chec.ed.

The statements which are used to e ecute only specific bloc. of statements in a series of bloc.s are called case control statements. There are 8 types of case control statements in C language. They are, 1. 2. 3. 8. switch brea. continue goto

$. s itc! case statement in C:


Switch case statements are used to e ecute only specific case statements based on the switch e pression. Below is the synta for switch case statement. switch !e pression# $ case label1* statements" brea." case label2* statements" brea." default* statements" brea." %

) ample program for switch..case statement in C*

5include 1stdio.h/

int main !# $ int value + 3"

switch!value# $ case 1* printf!6>alue is 1 =n6 #" brea." case 2* printf!6>alue is 2 =n6 #" brea." case 3* printf!6>alue is 3 =n6 #" brea." case 8* printf!6>alue is 8 =n6 #" brea." default * printf!6>alue is other than 1,2,3,8 =n6 #" %

return ," %

Output:
>alue is 3

%. brea& statement in C:

Brea. statement is used to terminate the while loops, switch case loops and for loops from the subseCuent e ecution. Syntax: brea&'

Example program for brea& statement in C:


5include 1stdio.h/ int main!# $ int i" for!i+,"i11,"i33# $ if!i++0# $ printf!6=nComing out of for loop when i + 06#" brea." % printf!67d 6,i#" %

% Output:
,1238 Coming out of for loop when i + 0

(. Continue statement in C:
Continue statement is used to continue the ne t iteration of for loop, while loop and do-while loops. So, the remaining statements are s.ipped within the loop for that particular iteration. Syntax : continue'

Example program for continue statement in C:

5include 1stdio.h/ int main!# $ int i" for!i+,"i11,"i33# $ if!i++0 DD i++9# $ printf!6=nS.ipping 7d from display using 6 = 6continue statement =n6,i#" continue" % printf!67d 6,i#" % % Output:
,1238 S.ipping 0 from display using continue statement S.ipping 9 from display using continue statement :;<

). goto statement in C:
goto statements is used to transfer the normal flow of a program to the specified label in the program. Below is the synta for goto statement in C.

$ EE. go to label"

EE. EE. @AB)@* statements" %

Example program for goto statement in C: 5include 1stdio.h/ int main!# $ int i" for!i+,"i11,"i33# $ if!i++0# $ printf!6=n&e are using goto statement when i + 06#" goto FA4" % printf!67d 6,i#" % FA4 * printf!6=nGow, we are inside label name =6hai=6 =n6#" % Output:
,1238 &e are using goto statement when i + 0 Gow, we are inside label name HhaiI

You might also like