SlideShare a Scribd company logo
Control structures control the flow of execution in a program or
function.
There are three kinds of execution flow:
– Sequence:
• the execution of the program is sequential.
– Selection:
• A control structure which chooses alternative to
execute.
– Repetition:
• A control structure which repeats a group of
statements.
Control
Structures in C
A program may choose among alternative statements by testing the value
of key variables.
– e.g., if( your_grade > 60 )
printf(“you are passed!”);
Condition is an expression that is either false (represented by 0) or true
(represented by 1).
– e.g., “your_grade > 60” is a condition.
Conditions may contain relational or equality operators, and have the
following forms.
– variable relational-operator variable (or constant)
– variable equality-operator variable (or constant)
Conditions
Operator Meaning Type
< Less than Relational
> Greater than Relational
<= Less than or equal to Relational
>= Greater than or equal
to
Relational
== Equal to Equality
!= Not equal to Equality
Operators Used in Conditions
Operator Condition Meaning
<= x <= 0 x less than or
equal to 0
< Power < MAX_POW Power less than
MAX_POW
== mom_or_dad == ‘M’ mom_or_dad
equal to ‘M’
!= num != SETINEL num not equal
to SETINEL
Examples of Conditions
Logical
Operators
There are three kinds of
logical operators.
– &&: and
– ||: or
– !: not
Logical expression is an
expression which uses one or
more logical operators, e.g.,
– (temperature > 90.0 &&
humidity > 0.90)
– !(n <= 0 || n >= 100).
Op 1 Op 2 Op 1 && Op2 Op 1 || Op2
nonzero nonzero 1 1
nonzero 0 0 1
0 nonzero 0 1
0 0 0 0
Op 1 ! Op 1
nonzero 0
0 1
The Truth Table of Logical Operators
The if statement is the primary selection control structure.
Syntax: if (condition) statement;
else statement;
An example of two alternatives:
if ( rest_heart_rate > 56 )
printf(“Keep up your exercise program!n”);
else
printf(“Your heart is in excellent health!n”);
An example of one alternative:
if ( x != 0.0 )
product = product * x;
The if
Statement
Decision Decision
Flowcharts of if Statements with (a) Two
Alternatives and (b) One Alternative
Nested if statement is an if statement with
another if statement as its true task or false
task. e.g.,
if (road_status == ‘S’)
else
printf(“Drive carefully!n”);
if (temp > 0) {
printf(“Wet roads ahead!n”);
}else{
printf(“Icy roads ahead!n”);
}
Nested if Statements
Another if statement
Main if statement
An Example for the Flowchart of
Nested if Statements
If there are many alternatives, it is better to use the
syntax of multiple-alternative decision.
Syntax:
if (condition1)
statement1
else if (condition2)
statement2
…
else if (conditionn)
statementn
else
statemente
Multiple-
Alternative
Decisions
An Example of Multiple-Alternative
Decisions
The switch statement is used to select one of several
alternatives when the selection is based on the value of a single
variable or an expression. switch (controlling expression) {
case label1:
statement1
break;
case label2:
statement2
break;
…
case labeln:
statementn
break;
default:
statementd;
}
If the result of this controlling expression
matches label1, execute staement1 and then break
this switch block.
If the result matches none of all labels, execute t
default statementd.
The switch Statement
class is a char variable.
Two or more cases can execute the same
statement.
An Example of a switch Statement with
Type char Case Labels

More Related Content

Similar to Decision control

LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
Aami Kakakhel
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
chintupro9
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
University of Potsdam
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
Ch05.pdf
Ch05.pdfCh05.pdf
Control statements anil
Control statements anilControl statements anil
Control statements anil
Anil Dutt
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
Anjali127411
 
Control structures in C
Control structures in CControl structures in C
Control statments in c
Control statments in cControl statments in c
Control statments in c
CGC Technical campus,Mohali
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
sshhzap
 
control structure
control structurecontrol structure
control structure
sivasankaravadivuN
 
Selection structure
Selection structureSelection structure
Selection structure
Jyoti Pokharna
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5
patcha535
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
dplunkett
 
Bsit1
Bsit1Bsit1
Bsit1
jigeno
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
shhanks
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
MURALIDHAR R
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
ssuserfb3c3e
 
M C6java5
M C6java5M C6java5
M C6java5
mbruggen
 

Similar to Decision control (20)

LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Ch05.pdf
Ch05.pdfCh05.pdf
Ch05.pdf
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
control structure
control structurecontrol structure
control structure
 
Selection structure
Selection structureSelection structure
Selection structure
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
 
Bsit1
Bsit1Bsit1
Bsit1
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
M C6java5
M C6java5M C6java5
M C6java5
 

More from Dr.Subha Krishna

Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
 
Programming questions
Programming questionsProgramming questions
Programming questions
Dr.Subha Krishna
 
Programming qns
Programming qnsProgramming qns
Programming qns
Dr.Subha Krishna
 
Programming egs
Programming egs Programming egs
Programming egs
Dr.Subha Krishna
 
Functions
Functions Functions
Functions
Dr.Subha Krishna
 
C Tutorial
C TutorialC Tutorial
C Tutorial
Dr.Subha Krishna
 

More from Dr.Subha Krishna (6)

Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Programming questions
Programming questionsProgramming questions
Programming questions
 
Programming qns
Programming qnsProgramming qns
Programming qns
 
Programming egs
Programming egs Programming egs
Programming egs
 
Functions
Functions Functions
Functions
 
C Tutorial
C TutorialC Tutorial
C Tutorial
 

Recently uploaded

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 

Recently uploaded (20)

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 

Decision control

  • 1. Control structures control the flow of execution in a program or function. There are three kinds of execution flow: – Sequence: • the execution of the program is sequential. – Selection: • A control structure which chooses alternative to execute. – Repetition: • A control structure which repeats a group of statements. Control Structures in C
  • 2. A program may choose among alternative statements by testing the value of key variables. – e.g., if( your_grade > 60 ) printf(“you are passed!”); Condition is an expression that is either false (represented by 0) or true (represented by 1). – e.g., “your_grade > 60” is a condition. Conditions may contain relational or equality operators, and have the following forms. – variable relational-operator variable (or constant) – variable equality-operator variable (or constant) Conditions
  • 3. Operator Meaning Type < Less than Relational > Greater than Relational <= Less than or equal to Relational >= Greater than or equal to Relational == Equal to Equality != Not equal to Equality Operators Used in Conditions
  • 4. Operator Condition Meaning <= x <= 0 x less than or equal to 0 < Power < MAX_POW Power less than MAX_POW == mom_or_dad == ‘M’ mom_or_dad equal to ‘M’ != num != SETINEL num not equal to SETINEL Examples of Conditions
  • 5. Logical Operators There are three kinds of logical operators. – &&: and – ||: or – !: not Logical expression is an expression which uses one or more logical operators, e.g., – (temperature > 90.0 && humidity > 0.90) – !(n <= 0 || n >= 100).
  • 6. Op 1 Op 2 Op 1 && Op2 Op 1 || Op2 nonzero nonzero 1 1 nonzero 0 0 1 0 nonzero 0 1 0 0 0 0 Op 1 ! Op 1 nonzero 0 0 1 The Truth Table of Logical Operators
  • 7. The if statement is the primary selection control structure. Syntax: if (condition) statement; else statement; An example of two alternatives: if ( rest_heart_rate > 56 ) printf(“Keep up your exercise program!n”); else printf(“Your heart is in excellent health!n”); An example of one alternative: if ( x != 0.0 ) product = product * x; The if Statement
  • 8. Decision Decision Flowcharts of if Statements with (a) Two Alternatives and (b) One Alternative
  • 9. Nested if statement is an if statement with another if statement as its true task or false task. e.g., if (road_status == ‘S’) else printf(“Drive carefully!n”); if (temp > 0) { printf(“Wet roads ahead!n”); }else{ printf(“Icy roads ahead!n”); } Nested if Statements
  • 10. Another if statement Main if statement An Example for the Flowchart of Nested if Statements
  • 11. If there are many alternatives, it is better to use the syntax of multiple-alternative decision. Syntax: if (condition1) statement1 else if (condition2) statement2 … else if (conditionn) statementn else statemente Multiple- Alternative Decisions
  • 12. An Example of Multiple-Alternative Decisions
  • 13. The switch statement is used to select one of several alternatives when the selection is based on the value of a single variable or an expression. switch (controlling expression) { case label1: statement1 break; case label2: statement2 break; … case labeln: statementn break; default: statementd; } If the result of this controlling expression matches label1, execute staement1 and then break this switch block. If the result matches none of all labels, execute t default statementd. The switch Statement
  • 14. class is a char variable. Two or more cases can execute the same statement. An Example of a switch Statement with Type char Case Labels