SlideShare a Scribd company logo
CONTROL STATEMENTS
LEARNING OBJECTIVES
 Understanding meaning of a statement and
statement block.
 Learn about decision type control constructs in C
and the way these are used.
 Learn about looping type control constructs in C
and the technique of putting them to use.
 Learn the use of special control constructs such as
goto, break, continue, and return.
 Learn about nested loops and their utility.
CONTROL STATEMENTS INCLUDE
Selection
Statements
• if
• if-else
• switch
Iteration
Statements
• for
• while
• do-while
Jump
Statements
• goto
• break
• continue
• return
PROGRAM CONTROL
STATEMENTS/CONSTRUCTS
Program Control
Statements/Constructs
Selection/Branching
Conditional
Type
if if-else
if-else-
if
switch
Unconditional
Type
break continue goto
Iteration/Looping
for while
do-
while
CONDITIONAL EXECUTION AND
SELECTION
• Selection Statements
• The Conditional Operator
• The switch Statement
SELECTION STATEMENTS
• One-way decisions using if statement
• Two-way decisions using if-else statement
• Multi-way decisions
• Dangling else Problem
ONE-WAY DECISIONS USING IF
STATEMENT
Flowchart for if construct
TestExpr
stmtT
WRITE A PROGRAM THAT PRINTS THE
LARGEST AMONG THREE NUMBERS.
Algorithm C Program
1. START #include <stdio.h>
int main()
{
int a, b, c, max;
printf(“nEnter 3 numbers”);
scanf(“%d %d %d”, &a, &b, &c);
max=a;
if(b>max)
max=b;
if(c>max)
max=c;
printf(“Largest No is %d”, max);
return 0;
}
2. PRINT “ENTER THREE
NUMBERS”
3. INPUT A, B, C
4. MAX=A
5. IF B>MAX THEN MAX=B
6. IF C>MAX THEN MAX=C
7. PRINT “LARGEST
NUMBER IS”, MAX
8. STOP
TWO-WAY DECISIONS USING
IF-ELSE STATEMENT
Flowchart of if-else construct
The form of a two-way
decision is as follows:
if(TestExpr)
stmtT;
else
stmtF;
TestExpr
stmtT stmtF
WRITE A PROGRAM THAT PRINTS THE
LARGEST AMONG THREE NUMBERS.
Algorithm C Program
1. START #include <stdio.h>
int main()
{
int a, b, c, max;
printf(“nEnter 3 numbers”);
scanf(“%d %d %d”, &a, &b, &c);
max=a;
if(b>max)
max=b;
if(c>max)
max=c;
printf(“Largest No is %d”, max);
return 0;
}
2. PRINT “ENTER THREE
NUMBERS”
3. INPUT A, B, C
4. MAX=A
5. IF B>MAX THEN MAX=B
6. IF C>MAX THEN MAX=C
7. PRINT “LARGEST
NUMBER IS”, MAX
8. STOP
MULTI-WAY DECISIONS
if-else-if ladder
if(TestExpr1)
stmtT1;
else if(TestExpr2)
stmtT2;
else if(TestExpr3)
stmtT3;
.. .
else if(TestExprN)
stmtTN;
else
stmtF;
General format of switch
statements
switch(expr)
{
case constant1: stmtList1;
break;
case constant2: stmtList2;
break;
case constant3: stmtList3;
break;
………………………….
………………………….
default: stmtListn;
}
FLOWCHART OF AN IF-
ELSE-IF CONSTRUCT
TestExpr
TestExpr2
TestExprN
TestExpr3
stmtT2
stmtTN
stmtT3
stmtTF
stmtT1
THE FOLLOWING PROGRAM CHECKS WHETHER A
NUMBER GIVEN BY THE USER IS ZERO, POSITIVE, OR
NEGATIVE
int main()
{
int x;
printf(“n ENTER THE NUMBER:”);
scanf(“%d”, &x);
if(x > 0)
printf(“x is positive n”);
else if(x == 0)
printf(“x is zero n”);
else
printf(“x is negative n”);
return 0;
NESTED IF
• When any if statement is
written under another if
statement, this cluster is
called a nested if.
• The syntax for the
nested is given here:
Construct 1 Construct 2
if(TestExprA)
if(TestExprB)
stmtBT;
else
stmtBF;
else
stmtAF;
if(TestExprA)
if(TestExprB)
stmtBT;
else
stmtBF;
else
if(TestExprC)
stmtCT;
else
stmtCF;
A PROGRAM TO FIND THE LARGEST AMONG
THREE NUMBERS USING THE NESTED LOOP
int main()
{
int a, b, c;
printf(“nEnter the three numbers”);
scanf(“%d %d %d”, &a, &b, &c);
if(a > b)
if(a > c)
printf(“%d”, a);
else
printf(“%d”, c);
else
if(b > c)
printf(“%d”, b);
else
printf(“%d”, c);
return 0;
}
DANGLING ELSE PROBLEM
• This classic problem occurs
when there is no matching
else for each if. To avoid this
problem, the simple C rule is
that always pair an else to the
most recent unpaired if in the
current block.
• The else is automatically
paired with the closest if.
But, it may be needed to
associate an else with the
outer if also.
SOLUTIONS TO DANGLING
ELSE PROBLEM
• Use of null else
• Use of braces to
enclose the true
action of the second if
With null else With braces
if(TestExprA)
if(TestExprB
)
stmtBT;
else
;
else
stmtAF;
if(TestExprA)
{
if(TestExprB
)
stmtBT;
}
else
stmtAF;
THE SWITCH STATEMENT
The C switch construct
switch(expr)
{
case constant1: stmtList1;
break;
case constant2: stmtList2;
break;
case constant3: stmtList3;
break;
………………………….
………………………….
default: stmtListn;
}
SWITCH VS NESTED IF
 The switch differs from the else-if in that switch can
test only for equality, whereas the if conditional
expression can be of a test expression involving any
type of relational operators and/or logical
operators.
 A switch statement is usually more efficient than
nested ifs.
 The switch statement can always be replaced with a
series of else-if statements.
ITERATION AND REPETITIVE
EXECUTION
• A loop allows one to execute
a statement or block of
statements repeatedly. There
are mainly two types of
iterations or loops –
unbounded iteration or
unbounded loop and bounded
iteration or bounded loop.
• A loop can either be a pre-test
loop or be a post-test loop as
illustrated in the diagram.
“WHILE” CONSTRUCT
Expanded Syntax of “while” and its
Flowchart Representation
• while statement is a
pretest loop. The basic
syntax of the while
statement is shown below:
AN EXAMPLE
#include <stdio.h>
int main()
{
int c;
c=5; // Initialization
while(c>0)
{ // Test Expression
printf(“ n %d”,c);
c=c-1; // Updating
}
return 0;
}
This loop contains all the
parts of a while loop. When
executed in a program, this
loop will output
5
4
3
2
1
TESTING FOR FLOATING-POINT
‘EQUALITY’
float x;
x = 0.0;
while(x != 1.1)
{
x = x + 0.1;
printf(“1.1 minus %f equals %.20gn”, x, 1.1 -x);
}
• The above loop never terminates on many computers,
because 0.1 cannot be accurately represented using
binary numbers.
• The correct way to make the test is to see if the two
numbers are ‘approximately equal’.
“FOR” CONSTRUCT
• The general form of the for statement is as follows:
for(initialization; TestExpr; updating)
statement;
for construct
flow chart
EXAMPLE
int main()
{
int n, s=0, r;
printf(“n Enter the Number”);
scanf(“%d”, &n);
for(;n>0;n/=10)
{
r=n%10;
s=s+r;
}
printf(“n Sum of digits %d”, s);
return 0;
}
“DO-WHILE” CONSTRUCT
• The form of this loop construct is as follows:
do
{
statement; /* body of statements would be
placed here*/
} while(TestExpression);
• With a do-while statement, the body of the loop is
executed first and the test expression is checked
after the loop body is executed.
• Thus, the do-while statement always executes the
loop body at least once.
#include <stdio.h>
int main()
{
int x = 1;
int count = 0;
do {
scanf(“%d”, &x);
if(x >= 0) count += 1;
} while(x >= 0);
return 0;
}
Some methods of controlling repetition in a
program are:
 Using Sentinel Values
 Using Prime Read
 Using Counter
GOTO STATEMENT
• The control is unconditionally transferred to
the statement associated with the label
specified in the goto statement.
• The form of a goto statement is
goto label_name;
The following program is used to find the factorial of a
number.
int main()
{
int n, c;
long int f=1;
printf(“n Enter the number:”);
scanf(“%d”,&n);
if(n<0)
goto end;
for(c=1; c<=n; c++)
f*=c;
printf(“n FACTORIAL IS %ld”, f);
end:
}
“BREAK” AND “CONTINUE”
break continue
1. It helps to make an early
exit from the block where it
appears.
1. It helps in avoiding the
remaining statements in a
current iteration of the loop
and continuing with the next
Iteration
2. It can be used in all control
statements including switch
construct.
2. It can be used only in loop
constructs.
NESTED LOOPS
 A nested loop refers to a
loop that is contained
within another loop.
 If the following output
has to be obtained on the
screen
1
2 2
3 3 3
4 4 4 4
then the corresponding
program will be
#include <stdio.h>
int main()
{
int row, col;
for(row=1;row<=4;++row)
{
for(col=1;col<=row;++col)
printf(“%d t”, row);
printf(“n”);
}
return 0;
}

More Related Content

PPT
Control statments in c
PDF
4_Decision Making and Branching in C Program.pdf
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
handling input output and control statements
PPTX
Btech i pic u-3 handling input output and control statements
PPTX
Mca i pic u-3 handling input output and control statements
PPTX
C Programming: Control Structure
Control statments in c
4_Decision Making and Branching in C Program.pdf
Bsc cs pic u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
handling input output and control statements
Btech i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
C Programming: Control Structure

Similar to C-Programming Control statements.pptx (20)

PPTX
unit2 C-ProgrammingChapter 2 Control statements.pptx
PDF
Controls & Loops in C
PPTX
CONTROL STMTS.pptx
PPT
Lecture 9- Control Structures 1
PPTX
C decision making and looping.
PPTX
C programming Control Structure.pptx
PDF
Module 2 - Control Structures c programming.pptm.pdf
PPTX
computer programming Control Statements.pptx
PPTX
Control structure of c
PPTX
C Programming - Decision making, Looping
PPTX
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
PDF
Workbook_2_Problem_Solving_and_programming.pdf
PDF
Unit 2=Decision Control & Looping Statements.pdf
PPT
2. Control structures with for while and do while.ppt
PPTX
C Unit-2.ppt
PPSX
Bsit1
PDF
Chapter 3 Computer Programmingodp-1_250331_041044.pdf
PDF
175035 cse lab-05
PPT
unit2 C-ProgrammingChapter 2 Control statements.pptx
Controls & Loops in C
CONTROL STMTS.pptx
Lecture 9- Control Structures 1
C decision making and looping.
C programming Control Structure.pptx
Module 2 - Control Structures c programming.pptm.pdf
computer programming Control Statements.pptx
Control structure of c
C Programming - Decision making, Looping
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
Workbook_2_Problem_Solving_and_programming.pdf
Unit 2=Decision Control & Looping Statements.pdf
2. Control structures with for while and do while.ppt
C Unit-2.ppt
Bsit1
Chapter 3 Computer Programmingodp-1_250331_041044.pdf
175035 cse lab-05
Ad

More from SKUP1 (20)

PPTX
serial_busses_i2c.pptx
PPTX
DESIGN PATTERN.pptx
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
C-Programming File-handling-C.pptx
PPTX
Processes, Threads.pptx
PPTX
Finite State Machine.ppt.pptx
PPTX
FUNCTIONS IN C.pptx
PPTX
cprogramming strings.pptx
PPTX
UNIONS IN C.pptx
PPTX
OPERATORS IN C.pptx
PPTX
cprogramming Structures.pptx
PPTX
C-Programming Function pointers.pptx
PPTX
POINTERS.pptx
PPTX
STACKS AND QUEUES.pptx
PPTX
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
PPTX
C MEMORY MODEL​.pptx
PPTX
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
PPTX
DYNAMIC MEMORY ALLOCATION.pptx
PPTX
COMPILATION PROCESS IN C.pptx
serial_busses_i2c.pptx
DESIGN PATTERN.pptx
INTER PROCESS COMMUNICATION (IPC).pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
C-Programming File-handling-C.pptx
Processes, Threads.pptx
Finite State Machine.ppt.pptx
FUNCTIONS IN C.pptx
cprogramming strings.pptx
UNIONS IN C.pptx
OPERATORS IN C.pptx
cprogramming Structures.pptx
C-Programming Function pointers.pptx
POINTERS.pptx
STACKS AND QUEUES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C MEMORY MODEL​.pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DYNAMIC MEMORY ALLOCATION.pptx
COMPILATION PROCESS IN C.pptx
Ad

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
master seminar digital applications in india
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Presentation on HIE in infants and its manifestations
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
master seminar digital applications in india
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Complications of Minimal Access Surgery at WLH
GDM (1) (1).pptx small presentation for students
Microbial disease of the cardiovascular and lymphatic systems
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Presentation on HIE in infants and its manifestations
102 student loan defaulters named and shamed – Is someone you know on the list?
Module 4: Burden of Disease Tutorial Slides S2 2025
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx

C-Programming Control statements.pptx

  • 2. LEARNING OBJECTIVES  Understanding meaning of a statement and statement block.  Learn about decision type control constructs in C and the way these are used.  Learn about looping type control constructs in C and the technique of putting them to use.  Learn the use of special control constructs such as goto, break, continue, and return.  Learn about nested loops and their utility.
  • 3. CONTROL STATEMENTS INCLUDE Selection Statements • if • if-else • switch Iteration Statements • for • while • do-while Jump Statements • goto • break • continue • return
  • 4. PROGRAM CONTROL STATEMENTS/CONSTRUCTS Program Control Statements/Constructs Selection/Branching Conditional Type if if-else if-else- if switch Unconditional Type break continue goto Iteration/Looping for while do- while
  • 5. CONDITIONAL EXECUTION AND SELECTION • Selection Statements • The Conditional Operator • The switch Statement
  • 6. SELECTION STATEMENTS • One-way decisions using if statement • Two-way decisions using if-else statement • Multi-way decisions • Dangling else Problem
  • 7. ONE-WAY DECISIONS USING IF STATEMENT Flowchart for if construct TestExpr stmtT
  • 8. WRITE A PROGRAM THAT PRINTS THE LARGEST AMONG THREE NUMBERS. Algorithm C Program 1. START #include <stdio.h> int main() { int a, b, c, max; printf(“nEnter 3 numbers”); scanf(“%d %d %d”, &a, &b, &c); max=a; if(b>max) max=b; if(c>max) max=c; printf(“Largest No is %d”, max); return 0; } 2. PRINT “ENTER THREE NUMBERS” 3. INPUT A, B, C 4. MAX=A 5. IF B>MAX THEN MAX=B 6. IF C>MAX THEN MAX=C 7. PRINT “LARGEST NUMBER IS”, MAX 8. STOP
  • 9. TWO-WAY DECISIONS USING IF-ELSE STATEMENT Flowchart of if-else construct The form of a two-way decision is as follows: if(TestExpr) stmtT; else stmtF; TestExpr stmtT stmtF
  • 10. WRITE A PROGRAM THAT PRINTS THE LARGEST AMONG THREE NUMBERS. Algorithm C Program 1. START #include <stdio.h> int main() { int a, b, c, max; printf(“nEnter 3 numbers”); scanf(“%d %d %d”, &a, &b, &c); max=a; if(b>max) max=b; if(c>max) max=c; printf(“Largest No is %d”, max); return 0; } 2. PRINT “ENTER THREE NUMBERS” 3. INPUT A, B, C 4. MAX=A 5. IF B>MAX THEN MAX=B 6. IF C>MAX THEN MAX=C 7. PRINT “LARGEST NUMBER IS”, MAX 8. STOP
  • 11. MULTI-WAY DECISIONS if-else-if ladder if(TestExpr1) stmtT1; else if(TestExpr2) stmtT2; else if(TestExpr3) stmtT3; .. . else if(TestExprN) stmtTN; else stmtF; General format of switch statements switch(expr) { case constant1: stmtList1; break; case constant2: stmtList2; break; case constant3: stmtList3; break; …………………………. …………………………. default: stmtListn; }
  • 12. FLOWCHART OF AN IF- ELSE-IF CONSTRUCT TestExpr TestExpr2 TestExprN TestExpr3 stmtT2 stmtTN stmtT3 stmtTF stmtT1
  • 13. THE FOLLOWING PROGRAM CHECKS WHETHER A NUMBER GIVEN BY THE USER IS ZERO, POSITIVE, OR NEGATIVE int main() { int x; printf(“n ENTER THE NUMBER:”); scanf(“%d”, &x); if(x > 0) printf(“x is positive n”); else if(x == 0) printf(“x is zero n”); else printf(“x is negative n”); return 0;
  • 14. NESTED IF • When any if statement is written under another if statement, this cluster is called a nested if. • The syntax for the nested is given here: Construct 1 Construct 2 if(TestExprA) if(TestExprB) stmtBT; else stmtBF; else stmtAF; if(TestExprA) if(TestExprB) stmtBT; else stmtBF; else if(TestExprC) stmtCT; else stmtCF;
  • 15. A PROGRAM TO FIND THE LARGEST AMONG THREE NUMBERS USING THE NESTED LOOP int main() { int a, b, c; printf(“nEnter the three numbers”); scanf(“%d %d %d”, &a, &b, &c); if(a > b) if(a > c) printf(“%d”, a); else printf(“%d”, c); else if(b > c) printf(“%d”, b); else printf(“%d”, c); return 0; }
  • 16. DANGLING ELSE PROBLEM • This classic problem occurs when there is no matching else for each if. To avoid this problem, the simple C rule is that always pair an else to the most recent unpaired if in the current block. • The else is automatically paired with the closest if. But, it may be needed to associate an else with the outer if also.
  • 17. SOLUTIONS TO DANGLING ELSE PROBLEM • Use of null else • Use of braces to enclose the true action of the second if With null else With braces if(TestExprA) if(TestExprB ) stmtBT; else ; else stmtAF; if(TestExprA) { if(TestExprB ) stmtBT; } else stmtAF;
  • 18. THE SWITCH STATEMENT The C switch construct switch(expr) { case constant1: stmtList1; break; case constant2: stmtList2; break; case constant3: stmtList3; break; …………………………. …………………………. default: stmtListn; }
  • 19. SWITCH VS NESTED IF  The switch differs from the else-if in that switch can test only for equality, whereas the if conditional expression can be of a test expression involving any type of relational operators and/or logical operators.  A switch statement is usually more efficient than nested ifs.  The switch statement can always be replaced with a series of else-if statements.
  • 20. ITERATION AND REPETITIVE EXECUTION • A loop allows one to execute a statement or block of statements repeatedly. There are mainly two types of iterations or loops – unbounded iteration or unbounded loop and bounded iteration or bounded loop. • A loop can either be a pre-test loop or be a post-test loop as illustrated in the diagram.
  • 21. “WHILE” CONSTRUCT Expanded Syntax of “while” and its Flowchart Representation • while statement is a pretest loop. The basic syntax of the while statement is shown below:
  • 22. AN EXAMPLE #include <stdio.h> int main() { int c; c=5; // Initialization while(c>0) { // Test Expression printf(“ n %d”,c); c=c-1; // Updating } return 0; } This loop contains all the parts of a while loop. When executed in a program, this loop will output 5 4 3 2 1
  • 23. TESTING FOR FLOATING-POINT ‘EQUALITY’ float x; x = 0.0; while(x != 1.1) { x = x + 0.1; printf(“1.1 minus %f equals %.20gn”, x, 1.1 -x); } • The above loop never terminates on many computers, because 0.1 cannot be accurately represented using binary numbers. • The correct way to make the test is to see if the two numbers are ‘approximately equal’.
  • 24. “FOR” CONSTRUCT • The general form of the for statement is as follows: for(initialization; TestExpr; updating) statement; for construct flow chart
  • 25. EXAMPLE int main() { int n, s=0, r; printf(“n Enter the Number”); scanf(“%d”, &n); for(;n>0;n/=10) { r=n%10; s=s+r; } printf(“n Sum of digits %d”, s); return 0; }
  • 26. “DO-WHILE” CONSTRUCT • The form of this loop construct is as follows: do { statement; /* body of statements would be placed here*/ } while(TestExpression);
  • 27. • With a do-while statement, the body of the loop is executed first and the test expression is checked after the loop body is executed. • Thus, the do-while statement always executes the loop body at least once.
  • 28. #include <stdio.h> int main() { int x = 1; int count = 0; do { scanf(“%d”, &x); if(x >= 0) count += 1; } while(x >= 0); return 0; }
  • 29. Some methods of controlling repetition in a program are:  Using Sentinel Values  Using Prime Read  Using Counter
  • 30. GOTO STATEMENT • The control is unconditionally transferred to the statement associated with the label specified in the goto statement. • The form of a goto statement is goto label_name;
  • 31. The following program is used to find the factorial of a number. int main() { int n, c; long int f=1; printf(“n Enter the number:”); scanf(“%d”,&n); if(n<0) goto end; for(c=1; c<=n; c++) f*=c; printf(“n FACTORIAL IS %ld”, f); end: }
  • 32. “BREAK” AND “CONTINUE” break continue 1. It helps to make an early exit from the block where it appears. 1. It helps in avoiding the remaining statements in a current iteration of the loop and continuing with the next Iteration 2. It can be used in all control statements including switch construct. 2. It can be used only in loop constructs.
  • 33. NESTED LOOPS  A nested loop refers to a loop that is contained within another loop.  If the following output has to be obtained on the screen 1 2 2 3 3 3 4 4 4 4 then the corresponding program will be #include <stdio.h> int main() { int row, col; for(row=1;row<=4;++row) { for(col=1;col<=row;++col) printf(“%d t”, row); printf(“n”); } return 0; }