SlideShare a Scribd company logo
Programming
Control Statement
Introduction
We have seen that a C program is a set of statement which are
normally executed in order which they appear. This happens when
no options or no repetitions in calculations are necessary.
However in practice we have a number of situations, where we
may have to change the order of execution of statements based
on certain conditions, or repeat a group of statements until
certain specified conditions are met.
This involves a kind of decision making to see whether a particular
conditions has occurred or not and then direct the computer to
execute certain statements accordingly.
C language processes such decision-making capabilities by
supporting the following statements.
1. if else statement
2. nested if else statement, if-else-if ladder
3. switch statement, Conditional operator statement
4. goto statement
These statements are popularly known as decision-making
statements. Since these statements ‘control’ the flow execution,
they are also known as control statement.
We have already used some of these statements in the earlier
examples. Here, we shall discuss their features, capabilities and
applications in more detail.
THE IF….ELSE STATEMENT
The if...else statement is an extension of the simple if statement. The general from is
If the test expression is true ,then the true-block statement(s), immediately following the if
statement are execute; otherwise, the false-block statement are executed, not both .this is
illustrated in fig in both the cases , the control is transferred subsequently to the statement.
if (test expression)
{
true-blockstatement(s)
}
else
{
false-blockstatement(s)
}
statement-x
#include<stdio.h>
int main()
{
int number = 5;
if(number >= 5) {
printf("Your number greater than 5 or
equal to 5n");
}
else{
printf("Your number is smaller than
5n");
}
return 0;
}
+
Code Output
CONCEPT
• The user already assigned the value of number is 5.
• When user run the code the user can see the output Your
number is greater than 5 or equal to 5.
The goto statement
• A goto statement in C language provides an unconditional jump from the goto
to a labeled statement in the same function.
• The given label must reside in the same function.
• Syntax:
• Here label can be any plain text except C keyword and it can be set anywhere
in the C program above or below to goto statement.
NOTE: Use of goto statement is highly discouraged in any programming language
because it makes difficult to trace the control flow of a program, making the
program hard to understand and hard to modify. Any program that uses a goto
can be rewritten so that it doesn't need the goto.
Goto statement Flow Diagram
Code Example: goto statement
#include<stdio.h>
int main()
{
int a;
printf("Enter the value of a: ");
scanf("%d", &a);
start:
printf("%dn", a);
a++;
if(a < 10)
goto start;
return 0;
}
Nested if-else Statements
 Using “if…else statement” within another “if…else statement”
is called ‘nested if statement’. “Nested if statements” is
mainly used to test multiple conditions.
 Structure:
if (test_condition){
if (test_condition)
{
statement-block;
}
else
{
statement-block;
}
}else
{
statement-block;
}
statement-x;
Nested if else
Example and the Flowchart of Nested if else
Statements
if (road_status == ‘S’){
if (temp > 0) {
printf(“Wet roads ahead!n”);
}else{
printf(“Icy roads ahead!n”);
}
else
printf(“Drive carefully!n”);
Another if-else statement
Main if-else statement
if-else-if ladder
 The word ladder means the staircase. As the name implies this
statement is used to choose right way among multiple paths.
 Syntax:
if (condition1)
statement1
else if (condition2)
statement2
……………………………
else if (conditionn)
statementn
else
statemente
Example:
if(Mark>=50 && Mark<60)
{ printf("Your grade is D");
}
else if(Mark>=60 && Mark<70)
{ printf("Your grade is C n");
}
else if(Mark>=70 && Mark<80)
{ printf("Your grade is B n");
}
else if(Mark>=80 && Mark<90)
{ printf("Your grade is A n");
}
else
printf("you have failed");
A switch statement allows a variable to be tested for equality
against a list of values. Each value is called a case, and the
variable being switched on is checked for each switch case.
Switch Case:
Flow Diagram :
How it works ?
 Switch case checks the value of expression/variable
against the list of case values and when the match is
found , the block of statement associated with that
case is executed
 Expression should be Integer Expression / Character
 Break statement takes control out of the case.
 Break Statement is Optional.
Example:
See how Switch Case works using Graphical
Picture
Control Statement programming

More Related Content

What's hot (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
baabtra.com - No. 1 supplier of quality freshers
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Recursion
RecursionRecursion
Recursion
Abdur Rehman
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
Dolchandra
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Branching in C
Branching in CBranching in C
Branching in C
Prabhu Govind
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
closure properties of regular language.pptx
closure properties of regular language.pptxclosure properties of regular language.pptx
closure properties of regular language.pptx
Thirumoorthy64
 
Break, Continue and Pass in Python.pdf
Break, Continue and Pass in Python.pdfBreak, Continue and Pass in Python.pdf
Break, Continue and Pass in Python.pdf
NehaSpillai1
 
Exceptions in python
Exceptions in pythonExceptions in python
Exceptions in python
baabtra.com - No. 1 supplier of quality freshers
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Python-Functions.pptx
Python-Functions.pptxPython-Functions.pptx
Python-Functions.pptx
Karudaiyar Ganapathy
 

Similar to Control Statement programming (20)

Control structure and Looping statements
Control structure and Looping statementsControl structure and Looping statements
Control structure and Looping statements
BalaKrishnan466
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
control-statements in C Language MH.pptx
control-statements in C Language MH.pptxcontrol-statements in C Language MH.pptx
control-statements in C Language MH.pptx
mehedi_hasan
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
ManojKhadilkar1
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
RanjeetaSharma8
 
control-statements, control-statements, control statement
control-statements, control-statements, control statementcontrol-statements, control-statements, control statement
control-statements, control-statements, control statement
crrpavankumar
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Dr. Chandrakant Divate
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
DEEPAK948083
 
C Programming: Control Statements in C Pgm
C Programming: Control Statements in C PgmC Programming: Control Statements in C Pgm
C Programming: Control Statements in C Pgm
Navya Francis
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
TejaswiB4
 
Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201
vpenubot
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
baabtra.com - No. 1 supplier of quality freshers
 
control-statements....ppt - definition
control-statements....ppt    -  definitioncontrol-statements....ppt    -  definition
control-statements....ppt - definition
Papitha7
 
Decision making in C(2020-2021) statements
Decision making in C(2020-2021) statementsDecision making in C(2020-2021) statements
Decision making in C(2020-2021) statements
BalaKrishnan466
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
JavvajiVenkat
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
FarshidKhan
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
Unit 2=Decision Control & Looping Statements.pdf
Unit 2=Decision Control & Looping Statements.pdfUnit 2=Decision Control & Looping Statements.pdf
Unit 2=Decision Control & Looping Statements.pdf
Dr. Ambedkar Institute of Technology, Bangalore 56
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Control structure and Looping statements
Control structure and Looping statementsControl structure and Looping statements
Control structure and Looping statements
BalaKrishnan466
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
control-statements in C Language MH.pptx
control-statements in C Language MH.pptxcontrol-statements in C Language MH.pptx
control-statements in C Language MH.pptx
mehedi_hasan
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
ManojKhadilkar1
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
RanjeetaSharma8
 
control-statements, control-statements, control statement
control-statements, control-statements, control statementcontrol-statements, control-statements, control statement
control-statements, control-statements, control statement
crrpavankumar
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Dr. Chandrakant Divate
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
DEEPAK948083
 
C Programming: Control Statements in C Pgm
C Programming: Control Statements in C PgmC Programming: Control Statements in C Pgm
C Programming: Control Statements in C Pgm
Navya Francis
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
TejaswiB4
 
Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201Unit-2 control Structures.pptx.pptx20201
Unit-2 control Structures.pptx.pptx20201
vpenubot
 
control-statements....ppt - definition
control-statements....ppt    -  definitioncontrol-statements....ppt    -  definition
control-statements....ppt - definition
Papitha7
 
Decision making in C(2020-2021) statements
Decision making in C(2020-2021) statementsDecision making in C(2020-2021) statements
Decision making in C(2020-2021) statements
BalaKrishnan466
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
FarshidKhan
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Ad

More from University of Potsdam (20)

Computer fundamentals 01
Computer fundamentals 01Computer fundamentals 01
Computer fundamentals 01
University of Potsdam
 
Workshop on android apps development
Workshop on android apps developmentWorkshop on android apps development
Workshop on android apps development
University of Potsdam
 
Transparency and concurrency
Transparency and concurrencyTransparency and concurrency
Transparency and concurrency
University of Potsdam
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
University of Potsdam
 
Functional dependency and normalization
Functional dependency and normalizationFunctional dependency and normalization
Functional dependency and normalization
University of Potsdam
 
indexing and hashing
indexing and hashingindexing and hashing
indexing and hashing
University of Potsdam
 
data recovery-raid
data recovery-raiddata recovery-raid
data recovery-raid
University of Potsdam
 
Query processing
Query processingQuery processing
Query processing
University of Potsdam
 
Machine Learning for Data Mining
Machine Learning for Data MiningMachine Learning for Data Mining
Machine Learning for Data Mining
University of Potsdam
 
Tree, function and graph
Tree, function and graphTree, function and graph
Tree, function and graph
University of Potsdam
 
Sonet
SonetSonet
Sonet
University of Potsdam
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
University of Potsdam
 
Set in discrete mathematics
Set in discrete mathematicsSet in discrete mathematics
Set in discrete mathematics
University of Potsdam
 
Series parallel ac rlc networks
Series parallel ac rlc networksSeries parallel ac rlc networks
Series parallel ac rlc networks
University of Potsdam
 
Series parallel ac networks
Series parallel ac networksSeries parallel ac networks
Series parallel ac networks
University of Potsdam
 
Relations
RelationsRelations
Relations
University of Potsdam
 
Relations
RelationsRelations
Relations
University of Potsdam
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
University of Potsdam
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
University of Potsdam
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
University of Potsdam
 
Ad

Recently uploaded (20)

Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT PatnaSwachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Quiz Club, Indian Institute of Technology, Patna
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
Types of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo SlidesTypes of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
Types of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo SlidesTypes of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo Slides
Celine George
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 

Control Statement programming

  • 2. Introduction We have seen that a C program is a set of statement which are normally executed in order which they appear. This happens when no options or no repetitions in calculations are necessary. However in practice we have a number of situations, where we may have to change the order of execution of statements based on certain conditions, or repeat a group of statements until certain specified conditions are met. This involves a kind of decision making to see whether a particular conditions has occurred or not and then direct the computer to execute certain statements accordingly.
  • 3. C language processes such decision-making capabilities by supporting the following statements. 1. if else statement 2. nested if else statement, if-else-if ladder 3. switch statement, Conditional operator statement 4. goto statement These statements are popularly known as decision-making statements. Since these statements ‘control’ the flow execution, they are also known as control statement. We have already used some of these statements in the earlier examples. Here, we shall discuss their features, capabilities and applications in more detail.
  • 4. THE IF….ELSE STATEMENT The if...else statement is an extension of the simple if statement. The general from is If the test expression is true ,then the true-block statement(s), immediately following the if statement are execute; otherwise, the false-block statement are executed, not both .this is illustrated in fig in both the cases , the control is transferred subsequently to the statement. if (test expression) { true-blockstatement(s) } else { false-blockstatement(s) } statement-x
  • 5. #include<stdio.h> int main() { int number = 5; if(number >= 5) { printf("Your number greater than 5 or equal to 5n"); } else{ printf("Your number is smaller than 5n"); } return 0; } + Code Output
  • 6. CONCEPT • The user already assigned the value of number is 5. • When user run the code the user can see the output Your number is greater than 5 or equal to 5.
  • 7. The goto statement • A goto statement in C language provides an unconditional jump from the goto to a labeled statement in the same function. • The given label must reside in the same function. • Syntax: • Here label can be any plain text except C keyword and it can be set anywhere in the C program above or below to goto statement. NOTE: Use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten so that it doesn't need the goto.
  • 9. Code Example: goto statement #include<stdio.h> int main() { int a; printf("Enter the value of a: "); scanf("%d", &a); start: printf("%dn", a); a++; if(a < 10) goto start; return 0; }
  • 10. Nested if-else Statements  Using “if…else statement” within another “if…else statement” is called ‘nested if statement’. “Nested if statements” is mainly used to test multiple conditions.  Structure: if (test_condition){ if (test_condition) { statement-block; } else { statement-block; } }else { statement-block; } statement-x; Nested if else
  • 11. Example and the Flowchart of Nested if else Statements if (road_status == ‘S’){ if (temp > 0) { printf(“Wet roads ahead!n”); }else{ printf(“Icy roads ahead!n”); } else printf(“Drive carefully!n”); Another if-else statement Main if-else statement
  • 12. if-else-if ladder  The word ladder means the staircase. As the name implies this statement is used to choose right way among multiple paths.  Syntax: if (condition1) statement1 else if (condition2) statement2 …………………………… else if (conditionn) statementn else statemente
  • 13. Example: if(Mark>=50 && Mark<60) { printf("Your grade is D"); } else if(Mark>=60 && Mark<70) { printf("Your grade is C n"); } else if(Mark>=70 && Mark<80) { printf("Your grade is B n"); } else if(Mark>=80 && Mark<90) { printf("Your grade is A n"); } else printf("you have failed");
  • 14. A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case. Switch Case: Flow Diagram :
  • 15. How it works ?  Switch case checks the value of expression/variable against the list of case values and when the match is found , the block of statement associated with that case is executed  Expression should be Integer Expression / Character  Break statement takes control out of the case.  Break Statement is Optional.
  • 17. See how Switch Case works using Graphical Picture