SlideShare a Scribd company logo
Handling
Input/output
&
Control StatementsCourse: MCA
Subject: Programming In C Language
CONTROL STATEMENTS
 C language supports the following statements known
as control or decision making statements.
1. if statement
2. switch statement
3. conditional operator statement
4. Go to statement
IF STATEMENT
 The if statement is used to control the flow of
execution of statements and is of the form
 If(test expression)
 Eg:
if(bank balance is zero)
Borrow money
Cont..
 The if statement may be implemented in different
forms depending on the complexity of conditions
to be tested.
1. Simple if statement
2. if…..else statement
3. Nested if…..else statement
4. elseif ladder
The general form of a simple
if statement is The
‘statement-block’ may be a
single statement or a group
of statement
If(test exprn)
{
statement-block;
}
statement-x;
Cont..
THE IF…ELSE STATEMENT
 The if….else statement is an extension of simple if
statement. The general form is
If(test expression)
{
True-block statement(s)
}
else
{
False-block statement(s)
}
statement-x
Cont..
 If the test expression is true, then the true block statements
are executed; otherwise the false block statement will be
executed.
Cont..
 Eg:
………
………
if(code ==1)
boy = boy + 1;
if(code == 2)
girl =girl + 1;
………
………
NESTING OF IF…..ELSE STATEMENTS
 When a series of decisions are involved, we may have
to use more than one if….else statements, in nested
form as follows
Cont..
Here, if the condition 1 is false then it
skipped to statement 3.
But if the condition 1 is true, then it
tests condition 2.

If condition 2 is true then it executes
statement 1 and if false then it executes
statement 2.
 Then the control is transferred to the
statement x.
This can also be shown by the following
flowchart,
Program
/*Selecting the largest of three values*/
main()
{
float A, B, C;
printf(“Enter three values n”);
scanf(“|%f %f %f”,&A, &B, &C);
printf(“nLargest value is:”);
if(A > B)
{ if(A > C)
printf(“%f n”,A);
else
printf(“%f n”,C);
}
else
{
if(C > B)
printf(“%f n”,C);
else
printf(“%f n”,B);
}
}
 OUTPUT
 Enter three values:
 5 8 24
 Largest value is 24
The else if ladder
When a multipath decision is involved then we use else if ladder.
 A multipath decision is a chain of ifs in which the statement associated
with each else is an if.
It takes the following general form,
Cont..
 This construct is known as the else if ladder. The conditions are
evaluated from the top, downwards. This can be shown by the
following flowchart
THE SWITCH STATEMENT
 Switch statement is used for complex programs when
the number of alternatives increases.
 The switch statement tests the value of the given
variable against the list of case values and when a
match is found, a block of statements associated with
that case is executed.
SWITCH STATEMENT
 The general form of switch statement is
switch(expression)
{
case value-1:
block-1
break;
case value-2:
block-2
break;
…….
…….
default:
default-block
break;
}
statement-x;
Example:
index = marks / 10;
switch(index)
{
case 10:
case 9:
case 8:
grade = “Honours”;
break;
case 7:
case 6:
grade = “first division”;
break;
case 5:
grade = “second
division”;
break;
case 4:
grade = “third
division”;
break;
default:
grade = “first
division”; break
}
printf(“%s n”,grade);
………….
THE ?: OPERATOR
 The C language has an unusual operator, useful for making two-
way decisions.
 This operator is a combination of ? and : and takes three
operands.
 It is of the form exp1?exp2:exp 3
 Here exp1 is evaluated first. If it is true then the expression exp2 is
evaluated and becomes the value of the expression.
 If exp1 is false then exp3 is evaluated and its value becomes the
value of the expression.
Eg:
if(x < 0)
flag = 0;
else
flag = 1;
can be written as
flag = (x < 0)? 0 : 1;
UNCONDITIONAL STATEMENTS - THE GOTO STATEMENT
C supports the goto statement to
branchunconditionally from one point of the
program to another.
The goto requires a label in order to identify
the place where the branch is to be made.
A label is any valid variable name and
must be followed by a colon.
DECISION MAKING AND LOOPING
 In looping, a sequence of statements are executed until some
conditions for termination of the loop are satisfied.
 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 known
as the body of the loop and the other known as the control
statements.
Cont..
Depending on the position of the control statements in
the loop, a control structure may be classified either as an
entry-controlled loop or as the exit-controlled loop.
Loops In C
 The C language provides for three loop constructs for
performing loop operations.
 They are:
The while statement
The do statement
The for statement
THE WHILE STATEMENT
 The basic format of the while statement is
while(test condition)
{
body of the loop
}
 The while is an entry–controlled loop statement.
 The test-condition is evaluated and if the condition is true, then the
body of the loop is executed.
 After execution of the body, the test-condition is once again evaluated and
if it is true, the body is executed once again.
 This process of repeated execution of the body continues until the test-
condition finally becomes false and the control is transferred out of the loop.
Example of WHILE Loop
-----------
-----------
Body of the loop
test
condn?
while(test condition)
{
body of the loop
}
sum = 0;
n = 1;
while(n <= 10)
{
sum = sum + n* n;
n = n + 1;
}
printf(“sum = %d n”,sum);
-----------
-----------
THE DO STATEMENT
 In while loop the body of the loop may not be executed at
all if the condition is not satisfied at the very first attempt.
 Such situations can be handled with the help of the do
statement.
do
{
body of the loop
}
while(test condition);
Cont..
 Since the test-condition is evaluated at the bottom of the loop,
the do…..while construct provides an exit-controlled loop and
therefore the body of the loop is always executed at least once.
Eg:
-----------
do
{
printf(“Input a numbern”);
number = getnum();
}
while(number > 0);
-----------
THE FOR STATEMENT
 The for loop is another entry-controlled loop that
provides a more concise loop control structure
 The general form of the for loop is
for(initialization ; test-condition ; increment
{
body of the loop
}
Cont..
 The execution of the for statement is as follows:
 Initialization of the control variables is done first.
 The value of the control variable is tested using the test-condition.
 If the condition is true, the body of the loop is executed; otherwise
the loop is terminated and the execution continues with the
statement that immediately follows the loop.
 When the body of the loop is executed, the control is transferred
back to the for statement after evaluating the last statement in
the loop.
 Now, the control variable is either incremented or decremented as
per the condition.
For Statement
 Eg 1)
for(x = 0; x <= 9; x = x + 1)
{
printf)”%d”,x);
}
printf(“n”);
 The multiple arguments in the increment section are possible
and separated by commas.
Cont..
 Eg 2)
sum = 0;
for(i = 1; i < 20 && sum <100; ++i)
{
sum =sum + i;
printf(“%d %d n”,sum);
}
for(initialization ; test-condition ; increment
{
body of the loop
}
Nesting of For Loops
 C allows one for statement within another for
statement.
Cont..
 Eg:
 ----------
 ----------
 for(row = 1; row <= ROWMAX; ++row)
 {
 for(column = 1; column < = COLMAX; ++column)
 {
 y = row * column;
 printf(“%4d”, y);
 }
 printf(“n”);
 }
 ----------
 ----------
JUMPS IN LOOPS
 C permits a jump from one statement to another within a
loop as well as the jump outof a loop.
Jumping out of a Loop
 An early exit from a loop can be accomplished by using the
break statement or the goto statement.
 When the break statement is encountered inside a loop, the
loop is immediately exited and the program continues with
the statement immediately following the loop.
 When the loops are nested, the break would only exit from
the loop containing it. That is, the break will exit only a
single loop.
Skipping a part of a Loop
 Like the break statement, C supports another similar
statement called the continue statement.
 However, unlike the break which causes the loop to be
terminated, the continue, as the name implies, causes the
loop to be continued with the next iteration after skipping
any statements in between.
 The continue statement tells the compiler, “SKIP THE
FOLLOWING STATEMENTS AND CONTINUE WITH THE NEXT
ITERATION”.
 The format of the continue statement is simply
continue;
Bypassing and continuing I Loops
References
1. http://www.computer-books.us/c_0008.php
2. http://www.computer-books.us/c_0009
3. http://www.computer-books.us/c_2.php
4. www.tutorialspoint.com/cprogramming/cprogramming_pdf.
5. Programming in C by yashwant kanitkar
6. ANSI C by E.balagurusamy- TMG publication
7. Computer programming and Utilization by sanjay shah Mahajan Publication
8. www.cprogramming.com/books.html

More Related Content

PPTX
Btech i pic u-3 handling input output and control statements
PPTX
Bsc cs pic u-3 handling input output and control statements
PPTX
Diploma ii cfpc u-3 handling input output and control statements
PPTX
CONTROL STMTS.pptx
PDF
Unit II chapter 4 Loops in C
PPT
C++ chapter 4
PPTX
Looping Structures
PPTX
Flow control instructions
Btech i pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
CONTROL STMTS.pptx
Unit II chapter 4 Loops in C
C++ chapter 4
Looping Structures
Flow control instructions

What's hot (20)

PPTX
Flow of control C ++ By TANUJ
PPTX
Unit 5. Control Statement
PPTX
Decision Making Statement in C ppt
PDF
Control statements
PPT
Decision making and branching
PPTX
Programming Fundamentals
 
PPTX
Control and conditional statements
PDF
Controls & Loops in C
PPTX
Control Statement programming
PPTX
Selection Statements in C Programming
PPTX
COM1407: Program Control Structures – Repetition and Loops
PDF
Control statements anil
DOCX
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
PPT
Mesics lecture 6 control statement = if -else if__else
PPT
PPTX
Types of loops in c language
PDF
C++ control structure
PPT
The Three Basic Selection Structures in C++ Programming Concepts
Flow of control C ++ By TANUJ
Unit 5. Control Statement
Decision Making Statement in C ppt
Control statements
Decision making and branching
Programming Fundamentals
 
Control and conditional statements
Controls & Loops in C
Control Statement programming
Selection Statements in C Programming
COM1407: Program Control Structures – Repetition and Loops
Control statements anil
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
Mesics lecture 6 control statement = if -else if__else
Types of loops in c language
C++ control structure
The Three Basic Selection Structures in C++ Programming Concepts
Ad

Viewers also liked (19)

PPT
B.sc i bio tech u 1 operating system concept & computer generation
PPTX
Diploma Sem II Unit III Writing Skill
DOCX
Bjmc i, cp, unit-iii, media in contemporary india
PPT
B.sc (microbiology and biotechnology and biochemistry) ii inorganic chemistry...
PPTX
Mba 1 me u 2.5 wage differiance
PPTX
Diploma engg iv u-1.3 assertive, imperative, exclamatory sentences
PPT
Unit 1 interview management
PPT
Ll.b ii lot ii u-ii tort relating to property
PPTX
B.sc ii unit 2 pronunciation
PPT
B.sc cs-ii-u-1.7 digital logic circuits, digital component memory unit
PPTX
B.tech. i es unit 4 environment renewable and non renewable energy resources
DOCX
Bjmc i, igp, unit-iv, judicial activism
PPTX
B.Sc. Biochem II BPI Unit 4 Microscopy
PPTX
Mca & bca i fma u 4.1 cost -volume-profit analysis
PPT
Bba ii cam u i-operating system concept
PPTX
B.tech. ii engineering chemistry Unit-4 A chemical aspect of biotechnology
PPTX
B Sc Agri II Agricultural Extansion Unit 2 Agricultural Development Programmes
PPTX
Diploma i em u ii forces and its effects
DOCX
Unit 1 Introduction
B.sc i bio tech u 1 operating system concept & computer generation
Diploma Sem II Unit III Writing Skill
Bjmc i, cp, unit-iii, media in contemporary india
B.sc (microbiology and biotechnology and biochemistry) ii inorganic chemistry...
Mba 1 me u 2.5 wage differiance
Diploma engg iv u-1.3 assertive, imperative, exclamatory sentences
Unit 1 interview management
Ll.b ii lot ii u-ii tort relating to property
B.sc ii unit 2 pronunciation
B.sc cs-ii-u-1.7 digital logic circuits, digital component memory unit
B.tech. i es unit 4 environment renewable and non renewable energy resources
Bjmc i, igp, unit-iv, judicial activism
B.Sc. Biochem II BPI Unit 4 Microscopy
Mca & bca i fma u 4.1 cost -volume-profit analysis
Bba ii cam u i-operating system concept
B.tech. ii engineering chemistry Unit-4 A chemical aspect of biotechnology
B Sc Agri II Agricultural Extansion Unit 2 Agricultural Development Programmes
Diploma i em u ii forces and its effects
Unit 1 Introduction
Ad

Similar to Mca i pic u-3 handling input output and control statements (20)

PPT
2. Control structures with for while and do while.ppt
PDF
4_Decision Making and Branching in C Program.pdf
PPTX
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
PPT
control-statements, control-statements, control statement
PPT
control-statements....ppt - definition
PPTX
C language 2
PPTX
C Programming - Decision making, Looping
PDF
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PPTX
C Programming: Control Structure
PDF
PDF
PPT
Control Structure in C
PDF
Bt0067 c programming and data structures 1
PPTX
Cse lecture-7-c loop
PPTX
Control Structures in C
PPTX
Managing input and output operations & Decision making and branching and looping
PPTX
Condition Stmt n Looping stmt.pptx
PPTX
C programming Control Structure.pptx
PPTX
C Programming Control Structures(if,if-else)
2. Control structures with for while and do while.ppt
4_Decision Making and Branching in C Program.pdf
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
control-statements, control-statements, control statement
control-statements....ppt - definition
C language 2
C Programming - Decision making, Looping
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
C Programming: Control Structure
Control Structure in C
Bt0067 c programming and data structures 1
Cse lecture-7-c loop
Control Structures in C
Managing input and output operations & Decision making and branching and looping
Condition Stmt n Looping stmt.pptx
C programming Control Structure.pptx
C Programming Control Structures(if,if-else)

More from Rai University (20)

PDF
Brochure Rai University
PPT
Mm unit 4point2
PPT
Mm unit 4point1
PPT
Mm unit 4point3
PPT
Mm unit 3point2
PPTX
Mm unit 3point1
PPTX
Mm unit 2point2
PPT
Mm unit 2 point 1
PPT
Mm unit 1point3
PPT
Mm unit 1point2
PPTX
Mm unit 1point1
DOCX
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
PPTX
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
PPTX
Bsc agri 2 pae u-4.3 public expenditure
PPTX
Bsc agri 2 pae u-4.2 public finance
PPS
Bsc agri 2 pae u-4.1 introduction
PPT
Bsc agri 2 pae u-3.3 inflation
PPTX
Bsc agri 2 pae u-3.2 introduction to macro economics
PPTX
Bsc agri 2 pae u-3.1 marketstructure
PPTX
Bsc agri 2 pae u-3 perfect-competition
Brochure Rai University
Mm unit 4point2
Mm unit 4point1
Mm unit 4point3
Mm unit 3point2
Mm unit 3point1
Mm unit 2point2
Mm unit 2 point 1
Mm unit 1point3
Mm unit 1point2
Mm unit 1point1
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri 2 pae u-4.2 public finance
Bsc agri 2 pae u-4.1 introduction
Bsc agri 2 pae u-3.3 inflation
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri 2 pae u-3 perfect-competition

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Basic Mud Logging Guide for educational purpose
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Classroom Observation Tools for Teachers
VCE English Exam - Section C Student Revision Booklet
STATICS OF THE RIGID BODIES Hibbelers.pdf
GDM (1) (1).pptx small presentation for students
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
Abdominal Access Techniques with Prof. Dr. R K Mishra
Basic Mud Logging Guide for educational purpose
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
01-Introduction-to-Information-Management.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
O5-L3 Freight Transport Ops (International) V1.pdf
Sports Quiz easy sports quiz sports quiz
Computing-Curriculum for Schools in Ghana
Microbial diseases, their pathogenesis and prophylaxis
Classroom Observation Tools for Teachers

Mca i pic u-3 handling input output and control statements

  • 2. CONTROL STATEMENTS  C language supports the following statements known as control or decision making statements. 1. if statement 2. switch statement 3. conditional operator statement 4. Go to statement
  • 3. IF STATEMENT  The if statement is used to control the flow of execution of statements and is of the form  If(test expression)  Eg: if(bank balance is zero) Borrow money
  • 4. Cont..  The if statement may be implemented in different forms depending on the complexity of conditions to be tested. 1. Simple if statement 2. if…..else statement 3. Nested if…..else statement 4. elseif ladder
  • 5. The general form of a simple if statement is The ‘statement-block’ may be a single statement or a group of statement If(test exprn) { statement-block; } statement-x; Cont..
  • 6. THE IF…ELSE STATEMENT  The if….else statement is an extension of simple if statement. The general form is If(test expression) { True-block statement(s) } else { False-block statement(s) } statement-x
  • 7. Cont..  If the test expression is true, then the true block statements are executed; otherwise the false block statement will be executed.
  • 8. Cont..  Eg: ……… ……… if(code ==1) boy = boy + 1; if(code == 2) girl =girl + 1; ……… ………
  • 9. NESTING OF IF…..ELSE STATEMENTS  When a series of decisions are involved, we may have to use more than one if….else statements, in nested form as follows
  • 10. Cont.. Here, if the condition 1 is false then it skipped to statement 3. But if the condition 1 is true, then it tests condition 2.  If condition 2 is true then it executes statement 1 and if false then it executes statement 2.  Then the control is transferred to the statement x. This can also be shown by the following flowchart,
  • 11. Program /*Selecting the largest of three values*/ main() { float A, B, C; printf(“Enter three values n”); scanf(“|%f %f %f”,&A, &B, &C); printf(“nLargest value is:”); if(A > B) { if(A > C) printf(“%f n”,A); else printf(“%f n”,C); } else { if(C > B) printf(“%f n”,C); else printf(“%f n”,B); } }  OUTPUT  Enter three values:  5 8 24  Largest value is 24
  • 12. The else if ladder When a multipath decision is involved then we use else if ladder.  A multipath decision is a chain of ifs in which the statement associated with each else is an if. It takes the following general form,
  • 13. Cont..  This construct is known as the else if ladder. The conditions are evaluated from the top, downwards. This can be shown by the following flowchart
  • 14. THE SWITCH STATEMENT  Switch statement is used for complex programs when the number of alternatives increases.  The switch statement tests the value of the given variable against the list of case values and when a match is found, a block of statements associated with that case is executed.
  • 15. SWITCH STATEMENT  The general form of switch statement is switch(expression) { case value-1: block-1 break; case value-2: block-2 break; ……. ……. default: default-block break; } statement-x;
  • 16. Example: index = marks / 10; switch(index) { case 10: case 9: case 8: grade = “Honours”; break; case 7: case 6: grade = “first division”; break; case 5: grade = “second division”; break; case 4: grade = “third division”; break; default: grade = “first division”; break } printf(“%s n”,grade); ………….
  • 17. THE ?: OPERATOR  The C language has an unusual operator, useful for making two- way decisions.  This operator is a combination of ? and : and takes three operands.  It is of the form exp1?exp2:exp 3  Here exp1 is evaluated first. If it is true then the expression exp2 is evaluated and becomes the value of the expression.  If exp1 is false then exp3 is evaluated and its value becomes the value of the expression. Eg: if(x < 0) flag = 0; else flag = 1; can be written as flag = (x < 0)? 0 : 1;
  • 18. UNCONDITIONAL STATEMENTS - THE GOTO STATEMENT C supports the goto statement to branchunconditionally from one point of the program to another. The goto requires a label in order to identify the place where the branch is to be made. A label is any valid variable name and must be followed by a colon.
  • 19. DECISION MAKING AND LOOPING  In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied.  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 known as the body of the loop and the other known as the control statements.
  • 20. Cont.. Depending on the position of the control statements in the loop, a control structure may be classified either as an entry-controlled loop or as the exit-controlled loop.
  • 21. Loops In C  The C language provides for three loop constructs for performing loop operations.  They are: The while statement The do statement The for statement
  • 22. THE WHILE STATEMENT  The basic format of the while statement is while(test condition) { body of the loop }  The while is an entry–controlled loop statement.  The test-condition is evaluated and if the condition is true, then the body of the loop is executed.  After execution of the body, the test-condition is once again evaluated and if it is true, the body is executed once again.  This process of repeated execution of the body continues until the test- condition finally becomes false and the control is transferred out of the loop.
  • 23. Example of WHILE Loop ----------- ----------- Body of the loop test condn? while(test condition) { body of the loop } sum = 0; n = 1; while(n <= 10) { sum = sum + n* n; n = n + 1; } printf(“sum = %d n”,sum); ----------- -----------
  • 24. THE DO STATEMENT  In while loop the body of the loop may not be executed at all if the condition is not satisfied at the very first attempt.  Such situations can be handled with the help of the do statement. do { body of the loop } while(test condition);
  • 25. Cont..  Since the test-condition is evaluated at the bottom of the loop, the do…..while construct provides an exit-controlled loop and therefore the body of the loop is always executed at least once. Eg: ----------- do { printf(“Input a numbern”); number = getnum(); } while(number > 0); -----------
  • 26. THE FOR STATEMENT  The for loop is another entry-controlled loop that provides a more concise loop control structure  The general form of the for loop is for(initialization ; test-condition ; increment { body of the loop }
  • 27. Cont..  The execution of the for statement is as follows:  Initialization of the control variables is done first.  The value of the control variable is tested using the test-condition.  If the condition is true, the body of the loop is executed; otherwise the loop is terminated and the execution continues with the statement that immediately follows the loop.  When the body of the loop is executed, the control is transferred back to the for statement after evaluating the last statement in the loop.  Now, the control variable is either incremented or decremented as per the condition.
  • 28. For Statement  Eg 1) for(x = 0; x <= 9; x = x + 1) { printf)”%d”,x); } printf(“n”);  The multiple arguments in the increment section are possible and separated by commas.
  • 29. Cont..  Eg 2) sum = 0; for(i = 1; i < 20 && sum <100; ++i) { sum =sum + i; printf(“%d %d n”,sum); } for(initialization ; test-condition ; increment { body of the loop }
  • 30. Nesting of For Loops  C allows one for statement within another for statement.
  • 31. Cont..  Eg:  ----------  ----------  for(row = 1; row <= ROWMAX; ++row)  {  for(column = 1; column < = COLMAX; ++column)  {  y = row * column;  printf(“%4d”, y);  }  printf(“n”);  }  ----------  ----------
  • 32. JUMPS IN LOOPS  C permits a jump from one statement to another within a loop as well as the jump outof a loop. Jumping out of a Loop  An early exit from a loop can be accomplished by using the break statement or the goto statement.  When the break statement is encountered inside a loop, the loop is immediately exited and the program continues with the statement immediately following the loop.  When the loops are nested, the break would only exit from the loop containing it. That is, the break will exit only a single loop.
  • 33. Skipping a part of a Loop  Like the break statement, C supports another similar statement called the continue statement.  However, unlike the break which causes the loop to be terminated, the continue, as the name implies, causes the loop to be continued with the next iteration after skipping any statements in between.  The continue statement tells the compiler, “SKIP THE FOLLOWING STATEMENTS AND CONTINUE WITH THE NEXT ITERATION”.  The format of the continue statement is simply continue;
  • 35. References 1. http://www.computer-books.us/c_0008.php 2. http://www.computer-books.us/c_0009 3. http://www.computer-books.us/c_2.php 4. www.tutorialspoint.com/cprogramming/cprogramming_pdf. 5. Programming in C by yashwant kanitkar 6. ANSI C by E.balagurusamy- TMG publication 7. Computer programming and Utilization by sanjay shah Mahajan Publication 8. www.cprogramming.com/books.html