Professional Documents
Culture Documents
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
2 3
while do while
Output:
,123809:;<
Output:
3809:;<
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
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
5include 1stdio.h/
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&'
% 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'
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"
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