SlideShare a Scribd company logo
CONTROL FLOW
STATEMENTS
IN C PROGRAMMING LANGUAGE
CREATED BY
TARUN SHARMA
(LECTURER COMPUTER
SCIENCE)
WHAT IS CONTROL FLOW STATEMENTS
• A control flow statements is a primary concept in most high-
level programming languages. It is a block of code. More
specifically, control flow statements are blocks of code that
control the flow of a program. In other words, a control
structure is a container for a series of function calls,
instructions and statements.
2
TYPES OF CONTROL FLOW STATEMENTS
• There are three types of control flow statements:
• Branching / Decision Making Statements
• Iterative / Looping Statements
• Jumping Statements
3
CONTROL FLOW STATEMENTS
• Branching / Decision
Making Statements
• If Statements
• Simple If
• If else
• Nested if
• Else if ladder
• Switch Case Statement
• Conditional Operator
• Looping / Iterative
Statements
• Entry Control Loops
• While Loop
• For Loop
• Exit Control Loop
• Do While Loop
• Jumping Statements
• Break Statement
• Continue Statement
• Goto Statement
4
BRANCHING STATEMENTS
• C program executes program sequentially. Sometimes, a
program requires checking of certain conditions in program
execution. C provides various key condition statements to
check condition and execute statements according conditional
criteria. These statements are called as 'Decision Making
Statements' or 'Conditional Statements.'
5
TYPES OF CONDITIONAL STATEMENTS
• If Statement
• Simple If
• If Else Statement
• Nested If Statement
• Else If Ladder
• Switch Case Statements
• Conditional Operator
6
IF STATEMENTS – SIMPLE IF STATEMENT
• Takes an expression in parenthesis and a statement or block of
statements. If the expression is true then the statement or
block of statements gets executed otherwise these statements
are skipped.
• Syntax:
if(Condition)
{
Statements;
}
7
SIMPLE IF EXAMPLE
void main()
{
int a=5;
if(a%2==0)
{
printf(“number %d is even.”,a);
}
}
8
IF STATEMENT – IF ELSE STATEMENTS
• This is also one of the most useful conditional statement used
in C to check conditions.
• Syntax:
if(condition){
true statements;
}
else{
false statements;
}
9
EXAMPLE
void main()
{
int a=5;
if(a%2==0){
printf(“number %d is even”,a);
}
else{
printf(“number %d is odd”,a);
}
} 10
IF STATEMENT – NESTED IF STATEMENTS
• If within a If condition is called Nested If condition. It is a
conditional statement which is used when we want to check
more than 1 conditions at a time in a same program.
• Syntax:
11
IF STATEMENT – NESTED IF STATEMENTS -
SYNTAX
if(condition){
if(condition){
true statement;
}
else {
false statement;
}
}
else{
statements;
}
12
EXAMPLE
void main()
{
int a,b,c;
a=5, b=6, c=8;
if(a>b){
if(a>c){
printf(“a is big”);
}
else{
printf(“c is big”);
}
}
else{
if(b>c){
printf(“b is big”);
}
else{
printf(“c is big”);
}
getch();
} 13
IF STATEMENT – ELSE IF LADDER
• Else if() ladder is similar to if else control statement. Else if()
ladder is used to check for another condition if the previously
specified condition becomes false.
• Syntax:
14
IF STATEMENT – ELSE IF LADDER - SYNTAX
If(condition){
Statement;
}
Else if(condition){
Statement;
}
Else{
Statement;
}
15
EXAMPLE
void main()
{
int a,b,c;
a=5, b=6, c=7;
if(a>b && a>c){
printf(“a is big”);
}
else if(b>c){
printf(“b is big”);
}
else{
printf(“c is big”);
}
getch();
}
16
SWITCH CASE STATEMENTS
• This is a multiple or multiway branching decision making
statement. When we use nested if-else statement to check
more than 1 condition then the complexity of a program
increases in case of a lot of conditions. Thus, the program is
difficult to read and maintain. So to overcome this problem, C
provides 'switch case'. Switch case checks the value of a
expression against a case values, if condition matches the case
values then the control is transferred to that point.
• Syntax
17
SWITCH CASE STATEMENT - SYNTAX
switch(expression){
case exp1:
statement;
break;
case exp2:
statement;
break;
default;
statement;
} 18
EXAMPLE
void main()
{
char c=‘a’;
switch(c)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
printf(“character %c is
vowel”,c);
break;
default:
printf(“character %c is
constant”,c);
}
getch();
}
19
CONDITIONAL OPERATOR
• The ? : Operator is just like an if … else statement except that
because it is an operator you can use it within expressions. ?
: is a ternary operator in that it takes three values, this is the
only ternary operator C has.
• Syntax:
Condition-test? First-expression(true): second-
expression(false);
20
EXAMPLE
void main()
{
int a,b,c,d;
a=5, b=6, c=7;
d=((a>b && a>c)?a((b>c)?b:c));
printf(“greater number is ::%d”,d);
getch();
}
21
ITERATIONS / LOOPING STATEMENTS
• 'A loop' is a part of code of a program which is executed
repeatedly. A loop is used using condition. The repetition is
done until condition becomes true.
• There are two types of looping statements.
• Entry controlled loop
• While Loop
• For Loop
• Exit controlled loop
• Do While Loop 22
ENTRY CONTROL LOOP – WHILE LOOP
• This is an entry controlled looping statement. It is used to
repeat a block of statements until condition becomes true.
• Syntax:
while (condition){
Statements;
Increment/decrement;
}
23
EXAMPLE
void main()
{
int I;
clrscr();
i=1;
while(i<=10){
printf(“%dt”,i);
i++;
}
getch();
}
24
ENTRY CONTROL LOOP – FOR LOOP
• This is an entry controlled looping statement. In this loop
structure, more than one variable can be initialized. One of the
most important feature of this loop is that the three actions can
be taken at a time like variable initialization, condition checking
and increment/decrement.
• Syntax:
for(initialization; test-condition; increment/decrement)
{
Statements;
}
25
EXAMPLE
void main()
{
int i;
clrscr();
i=1;
for(i=1;i<=20; i+=2)
{
printf(“%dt”,i);
}
getch();
}
26
EXIT CONTROL – DO WHILE LOOP
• This is an exit controlled looping statement. Sometimes, there
is need to execute a block of statements first then to check
condition. At that time such type of a loop is used. In this,
block of statements are executed first and then condition is
checked.
• Syntax:
do {
Statements ;( increment/decrement);
} while (condition);
27
EXAMPLE
void main()
{
int I;
clrscr();
i=1;
do
{
printf(“%dt”,i);
i++;
}while(i<=5);
getch();
} 28
JUMPING STATEMENTS
• There are three types of jumping statements:
• Break
• Continue
• Goto
29
BREAK STATEMENT
• It is necessary to exit immediately from a loop as soon as the
condition is satisfied. When break statement is used inside a
loop, then it can cause to terminate from a loop. The
statements after break statement are skipped.
• Syntax:
if(condition)
{
break;
}
30
EXAMPLE
void main()
{
int i;
for(i=1;i<=10; i++){
If(i==5){
break;
}
else{
printf(“%dt”,i);
}
}
getch();
}
31
CONTINUE STATEMENT
• It is required to skip a part of a body of loop under specific
conditions. The working structure of 'continue' is similar as that
of that break statement but difference is that it cannot
terminate the loop. It causes the loop to be continued with next
iteration after skipping statements in between. Continue
statement simply skips statements and continues next
iteration.
• Syntax:
if(condition){
continue;
32
EXAMPLE
void main()
{
int i;
for(i=1;i<=10; i++){
If(i==5){
continue;
}
else{
printf(“%dt”,i);
}
}
getch();
}
33
GOTO STATEMENT
• The goto statement is a jump statement which jumps from one point
to another point within a function or program. The goto statement is
marked by label statement. Label statement can be used anywhere in
the function above or below the goto statement. Simple break
statement cannot work here properly. In this situation, goto
statement is used.
• Syntax:
if(condition){
goto err;
}
err:
statements;
34
EXAMPLE
void main()
{
int i;
for(i=1;i<=10; i++){
If(i==5){
goto err:
}
else{
printf(“%dt”,i);
}
}
err:
printf(“Error”);
}
35
THANK YOU
36

More Related Content

What's hot

Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
Rabin BK
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
savitamhaske
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
Siddique Ibrahim
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 

What's hot (20)

Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
C if else
C if elseC if else
C if else
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Loops c++
Loops c++Loops c++
Loops c++
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Data types in C
Data types in CData types in C
Data types in C
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 

Similar to Control Flow Statements

Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
Likhil181
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
SKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
LECO9
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
ssuserfb3c3e
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
CGC Technical campus,Mohali
 
Session 3
Session 3Session 3
Control statements anil
Control statements anilControl statements anil
Control statements anil
Anil Dutt
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
JavvajiVenkat
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
nikshaikh786
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
ayshasafdarwaada
 
Diploma ii cfpc u-3 handling input output and control statements
Diploma ii  cfpc u-3 handling input output and control statementsDiploma ii  cfpc u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
Rai University
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
Rai University
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
MURALIDHAR R
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdfModule 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
SudipDebnath20
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
Rai University
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
Rai University
 
Control Statement IN C.pptx
Control Statement IN C.pptxControl Statement IN C.pptx
Control Statement IN C.pptx
sujatha629799
 

Similar to Control Flow Statements (20)

Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Session 3
Session 3Session 3
Session 3
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
Diploma ii cfpc u-3 handling input output and control statements
Diploma ii  cfpc u-3 handling input output and control statementsDiploma ii  cfpc u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdfModule 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
 
Control Statement IN C.pptx
Control Statement IN C.pptxControl Statement IN C.pptx
Control Statement IN C.pptx
 

More from Tarun Sharma

C Token’s
C Token’sC Token’s
C Token’s
Tarun Sharma
 
C Question Paper Solution - MDSU Ajmer
C Question Paper Solution - MDSU AjmerC Question Paper Solution - MDSU Ajmer
C Question Paper Solution - MDSU Ajmer
Tarun Sharma
 
Armstrong numbers
Armstrong numbersArmstrong numbers
Armstrong numbers
Tarun Sharma
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
Tarun Sharma
 
Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C Language
Tarun Sharma
 
Remote Desktop Access
Remote Desktop AccessRemote Desktop Access
Remote Desktop AccessTarun Sharma
 
Generations of Programming Languages
Generations of Programming LanguagesGenerations of Programming Languages
Generations of Programming LanguagesTarun Sharma
 

More from Tarun Sharma (7)

C Token’s
C Token’sC Token’s
C Token’s
 
C Question Paper Solution - MDSU Ajmer
C Question Paper Solution - MDSU AjmerC Question Paper Solution - MDSU Ajmer
C Question Paper Solution - MDSU Ajmer
 
Armstrong numbers
Armstrong numbersArmstrong numbers
Armstrong numbers
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
 
Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C Language
 
Remote Desktop Access
Remote Desktop AccessRemote Desktop Access
Remote Desktop Access
 
Generations of Programming Languages
Generations of Programming LanguagesGenerations of Programming Languages
Generations of Programming Languages
 

Recently uploaded

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 

Recently uploaded (20)

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 

Control Flow Statements

  • 1. CONTROL FLOW STATEMENTS IN C PROGRAMMING LANGUAGE CREATED BY TARUN SHARMA (LECTURER COMPUTER SCIENCE)
  • 2. WHAT IS CONTROL FLOW STATEMENTS • A control flow statements is a primary concept in most high- level programming languages. It is a block of code. More specifically, control flow statements are blocks of code that control the flow of a program. In other words, a control structure is a container for a series of function calls, instructions and statements. 2
  • 3. TYPES OF CONTROL FLOW STATEMENTS • There are three types of control flow statements: • Branching / Decision Making Statements • Iterative / Looping Statements • Jumping Statements 3
  • 4. CONTROL FLOW STATEMENTS • Branching / Decision Making Statements • If Statements • Simple If • If else • Nested if • Else if ladder • Switch Case Statement • Conditional Operator • Looping / Iterative Statements • Entry Control Loops • While Loop • For Loop • Exit Control Loop • Do While Loop • Jumping Statements • Break Statement • Continue Statement • Goto Statement 4
  • 5. BRANCHING STATEMENTS • C program executes program sequentially. Sometimes, a program requires checking of certain conditions in program execution. C provides various key condition statements to check condition and execute statements according conditional criteria. These statements are called as 'Decision Making Statements' or 'Conditional Statements.' 5
  • 6. TYPES OF CONDITIONAL STATEMENTS • If Statement • Simple If • If Else Statement • Nested If Statement • Else If Ladder • Switch Case Statements • Conditional Operator 6
  • 7. IF STATEMENTS – SIMPLE IF STATEMENT • Takes an expression in parenthesis and a statement or block of statements. If the expression is true then the statement or block of statements gets executed otherwise these statements are skipped. • Syntax: if(Condition) { Statements; } 7
  • 8. SIMPLE IF EXAMPLE void main() { int a=5; if(a%2==0) { printf(“number %d is even.”,a); } } 8
  • 9. IF STATEMENT – IF ELSE STATEMENTS • This is also one of the most useful conditional statement used in C to check conditions. • Syntax: if(condition){ true statements; } else{ false statements; } 9
  • 10. EXAMPLE void main() { int a=5; if(a%2==0){ printf(“number %d is even”,a); } else{ printf(“number %d is odd”,a); } } 10
  • 11. IF STATEMENT – NESTED IF STATEMENTS • If within a If condition is called Nested If condition. It is a conditional statement which is used when we want to check more than 1 conditions at a time in a same program. • Syntax: 11
  • 12. IF STATEMENT – NESTED IF STATEMENTS - SYNTAX if(condition){ if(condition){ true statement; } else { false statement; } } else{ statements; } 12
  • 13. EXAMPLE void main() { int a,b,c; a=5, b=6, c=8; if(a>b){ if(a>c){ printf(“a is big”); } else{ printf(“c is big”); } } else{ if(b>c){ printf(“b is big”); } else{ printf(“c is big”); } getch(); } 13
  • 14. IF STATEMENT – ELSE IF LADDER • Else if() ladder is similar to if else control statement. Else if() ladder is used to check for another condition if the previously specified condition becomes false. • Syntax: 14
  • 15. IF STATEMENT – ELSE IF LADDER - SYNTAX If(condition){ Statement; } Else if(condition){ Statement; } Else{ Statement; } 15
  • 16. EXAMPLE void main() { int a,b,c; a=5, b=6, c=7; if(a>b && a>c){ printf(“a is big”); } else if(b>c){ printf(“b is big”); } else{ printf(“c is big”); } getch(); } 16
  • 17. SWITCH CASE STATEMENTS • This is a multiple or multiway branching decision making statement. When we use nested if-else statement to check more than 1 condition then the complexity of a program increases in case of a lot of conditions. Thus, the program is difficult to read and maintain. So to overcome this problem, C provides 'switch case'. Switch case checks the value of a expression against a case values, if condition matches the case values then the control is transferred to that point. • Syntax 17
  • 18. SWITCH CASE STATEMENT - SYNTAX switch(expression){ case exp1: statement; break; case exp2: statement; break; default; statement; } 18
  • 19. EXAMPLE void main() { char c=‘a’; switch(c) { case ‘a’: case ‘e’: case ‘i’: case ‘o’: case ‘u’: printf(“character %c is vowel”,c); break; default: printf(“character %c is constant”,c); } getch(); } 19
  • 20. CONDITIONAL OPERATOR • The ? : Operator is just like an if … else statement except that because it is an operator you can use it within expressions. ? : is a ternary operator in that it takes three values, this is the only ternary operator C has. • Syntax: Condition-test? First-expression(true): second- expression(false); 20
  • 21. EXAMPLE void main() { int a,b,c,d; a=5, b=6, c=7; d=((a>b && a>c)?a((b>c)?b:c)); printf(“greater number is ::%d”,d); getch(); } 21
  • 22. ITERATIONS / LOOPING STATEMENTS • 'A loop' is a part of code of a program which is executed repeatedly. A loop is used using condition. The repetition is done until condition becomes true. • There are two types of looping statements. • Entry controlled loop • While Loop • For Loop • Exit controlled loop • Do While Loop 22
  • 23. ENTRY CONTROL LOOP – WHILE LOOP • This is an entry controlled looping statement. It is used to repeat a block of statements until condition becomes true. • Syntax: while (condition){ Statements; Increment/decrement; } 23
  • 25. ENTRY CONTROL LOOP – FOR LOOP • This is an entry controlled looping statement. In this loop structure, more than one variable can be initialized. One of the most important feature of this loop is that the three actions can be taken at a time like variable initialization, condition checking and increment/decrement. • Syntax: for(initialization; test-condition; increment/decrement) { Statements; } 25
  • 26. EXAMPLE void main() { int i; clrscr(); i=1; for(i=1;i<=20; i+=2) { printf(“%dt”,i); } getch(); } 26
  • 27. EXIT CONTROL – DO WHILE LOOP • This is an exit controlled looping statement. Sometimes, there is need to execute a block of statements first then to check condition. At that time such type of a loop is used. In this, block of statements are executed first and then condition is checked. • Syntax: do { Statements ;( increment/decrement); } while (condition); 27
  • 29. JUMPING STATEMENTS • There are three types of jumping statements: • Break • Continue • Goto 29
  • 30. BREAK STATEMENT • It is necessary to exit immediately from a loop as soon as the condition is satisfied. When break statement is used inside a loop, then it can cause to terminate from a loop. The statements after break statement are skipped. • Syntax: if(condition) { break; } 30
  • 31. EXAMPLE void main() { int i; for(i=1;i<=10; i++){ If(i==5){ break; } else{ printf(“%dt”,i); } } getch(); } 31
  • 32. CONTINUE STATEMENT • It is required to skip a part of a body of loop under specific conditions. The working structure of 'continue' is similar as that of that break statement but difference is that it cannot terminate the loop. It causes the loop to be continued with next iteration after skipping statements in between. Continue statement simply skips statements and continues next iteration. • Syntax: if(condition){ continue; 32
  • 33. EXAMPLE void main() { int i; for(i=1;i<=10; i++){ If(i==5){ continue; } else{ printf(“%dt”,i); } } getch(); } 33
  • 34. GOTO STATEMENT • The goto statement is a jump statement which jumps from one point to another point within a function or program. The goto statement is marked by label statement. Label statement can be used anywhere in the function above or below the goto statement. Simple break statement cannot work here properly. In this situation, goto statement is used. • Syntax: if(condition){ goto err; } err: statements; 34
  • 35. EXAMPLE void main() { int i; for(i=1;i<=10; i++){ If(i==5){ goto err: } else{ printf(“%dt”,i); } } err: printf(“Error”); } 35