SlideShare a Scribd company logo
1 of 19
Hello!
Myself Archana R
Assistant Professor In
Dept Of CS
SACWC.
I am here because I love to
give presentations.
1
Decision Making And Branching
In Programming In C
INTRODUCTION
‘C’ language processes decision making capabilities supports the flowing
statements known as control or decision making statements
There are 4 Types:
●If statement
●switch statement
●conditional operator statement
●goto statement
3
If statement
 The if statement is powerful decision making
statement and is used to control the flow of execution
of statements.
 if statement is the most simple decision-making
statement. It is used to decide whether a certain
statement or block of statements will be
executed or not.
“
5
Types of if Statement
(a) Simple if statement
(b) If else statement
(d) Else –If ladder
5
(c) Nesting of If-else statement
Simple if Statement
If the test expression is true then a true block statement are executed,
otherwise the false – block statement are executed. In both cases
either true-block or false-block will be executed not both.
Syntax:
● if (test expression)
● {
statement block;
● }
statement-x ;
“
7
Flow Chart For Simple If Statement
7
 If the student belongs to the
sports category then additional bonus
marks are added to his marks before
they are printed. For others bonus
marks are not added .
8
Simple If Statement
Example
if (category = sports)
{
marks = marks + bonus marks;
}
printf(“%d”,marks);
If Else Statement
If the test expression is true then a true block statement are executed, otherwise the false block
statement are executed. In both cases either true-block or false-block will be executed not both.
Syntax:
if (test expression)
{
true-block statements;
}
else
{
false-block statements;
}
statement – x;
“
10
Flow Chart For If else Statement
10
 Here if the code is equal to ‘1’ the
statement boy=boy+1; Is executed and the control is
transferred to the statement st-n, after skipping the
else part. If code is not equal to ‘1’ the statement boy
=boy+1; is skipped and the statement in the else
part girl =girl+1; is executed before the control
reaches the statement st-n.
11
If else Statement
Example
If (code == 1)
boy = boy + 1;
else
girl = girl + 1;
st-x;
Nesting of if else statement
When a series of decisions are involved we may have to use more than one
if-else statement in nested form of follows.
Syntax: if ( Test Condition1) {
if ( Test Condition2) {
Statement -1;
}
else {
Statement -2; }
else {
Statement -3;}
}
“
13
Flow Chart For nesting of If else Statement
13
14
Nesting of If else Statement
Example
Else-If ladder
A multi path decision is charm of its in which the statement associated with
each else is an If. It takes the following general form.
This construct is known as the wise-If ladder. The conditions are evaluated
from the top of the ladder to down wards. As soon as a true condition is
found the statement associated with it is executed and the control the is
transferred to the st-X (i.e.., skipping the rest of the ladder). when all the n-
conditions become false then the final else containing the default – st will be
executed.
16
Else-If ladder
SYNTAX
if (Test Condition -1) {
Statement -1; }
else if ( Test Condition -2) {
Statement -2;}
else if ( Test Condition -3) {
Statement -3; }
else if ( Test Condition –n) {
Statement –n;
}else {
default statement; }
Statements-X;
17
Else-If ladder Flow Chart
“
18
18
The above construction is known as else if ladders.
The conditions are evaluated from top to bottom.
As soon as a true condition is found, the statement associated
with it is executed and
The control is transferred to the Rest of the Program
Statement–X (skipping rest of the ladder).
When all the “n” conditions become false, then the final else
containing the default statement will be executed.
Ex : If (code = = 1) Color = “red”;
Else if ( code = = 2) Color = “green”
Else if (code = = 3) Color = “white”;
Else Color = “yellow”;
If code number is other than 1,2 and 3 then color is yellow.
Else-If ladder
Thanks!
19

More Related Content

What's hot

Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programmingPriyansh Thakar
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationBadrul Alam
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in cMuthuganesh S
 
IF Statement
IF StatementIF Statement
IF StatementYunis20
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
While loop
While loopWhile loop
While loopFeras_83
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in JavaNiloy Saha
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1srmohan06
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 

What's hot (20)

CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
C tokens
C tokensC tokens
C tokens
 
IF Statement
IF StatementIF Statement
IF Statement
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Branching in C
Branching in CBranching in C
Branching in C
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
While loop
While loopWhile loop
While loop
 
Forloop
ForloopForloop
Forloop
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 

Similar to If statements in c programming

C statements
C statementsC statements
C statementsAhsann111
 
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.pptManojKhadilkar1
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdfRanjeetaSharma8
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsLovelitJose
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statementsrajshreemuthiah
 
Programming (if else)
Programming (if else)Programming (if else)
Programming (if else)Papon Sarker
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, LoopingMURALIDHAR R
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal Acharya
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docxJavvajiVenkat
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 

Similar to If statements in c programming (20)

Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
C statements
C statementsC statements
C statements
 
Selection structure
Selection structureSelection structure
Selection structure
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
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
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
UNIT 2 PPT.pdf
UNIT 2 PPT.pdfUNIT 2 PPT.pdf
UNIT 2 PPT.pdf
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Decision Making.pptx
Decision Making.pptxDecision Making.pptx
Decision Making.pptx
 
Programming (if else)
Programming (if else)Programming (if else)
Programming (if else)
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Selection statements
Selection statementsSelection statements
Selection statements
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 

More from Archana Gopinath

Data Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxData Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxArchana Gopinath
 
DP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxDP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxArchana Gopinath
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical AnalyzerArchana Gopinath
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyserArchana Gopinath
 
A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzersArchana Gopinath
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical AnalyzerArchana Gopinath
 
minimization the number of states of DFA
minimization the number of states of DFAminimization the number of states of DFA
minimization the number of states of DFAArchana Gopinath
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite AutomataArchana Gopinath
 
Fundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and HadoopFundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and HadoopArchana Gopinath
 
Map reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSMap reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSArchana Gopinath
 
Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data AnalyticsArchana Gopinath
 
Guided media Transmission Media
Guided media Transmission MediaGuided media Transmission Media
Guided media Transmission MediaArchana Gopinath
 

More from Archana Gopinath (18)

Data Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxData Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptx
 
DP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxDP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptx
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzers
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
minimization the number of states of DFA
minimization the number of states of DFAminimization the number of states of DFA
minimization the number of states of DFA
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Fundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and HadoopFundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and Hadoop
 
Map reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSMap reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICS
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
 
Hadoop
HadoopHadoop
Hadoop
 
Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
 
un Guided media
un Guided mediaun Guided media
un Guided media
 
Guided media Transmission Media
Guided media Transmission MediaGuided media Transmission Media
Guided media Transmission Media
 
Main Memory RAM and ROM
Main Memory RAM and ROMMain Memory RAM and ROM
Main Memory RAM and ROM
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 

Recently uploaded

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

If statements in c programming

  • 1. Hello! Myself Archana R Assistant Professor In Dept Of CS SACWC. I am here because I love to give presentations. 1
  • 2. Decision Making And Branching In Programming In C
  • 3. INTRODUCTION ‘C’ language processes decision making capabilities supports the flowing statements known as control or decision making statements There are 4 Types: ●If statement ●switch statement ●conditional operator statement ●goto statement 3
  • 4. If statement  The if statement is powerful decision making statement and is used to control the flow of execution of statements.  if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not.
  • 5. “ 5 Types of if Statement (a) Simple if statement (b) If else statement (d) Else –If ladder 5 (c) Nesting of If-else statement
  • 6. Simple if Statement If the test expression is true then a true block statement are executed, otherwise the false – block statement are executed. In both cases either true-block or false-block will be executed not both. Syntax: ● if (test expression) ● { statement block; ● } statement-x ;
  • 7. “ 7 Flow Chart For Simple If Statement 7
  • 8.  If the student belongs to the sports category then additional bonus marks are added to his marks before they are printed. For others bonus marks are not added . 8 Simple If Statement Example if (category = sports) { marks = marks + bonus marks; } printf(“%d”,marks);
  • 9. If Else Statement If the test expression is true then a true block statement are executed, otherwise the false block statement are executed. In both cases either true-block or false-block will be executed not both. Syntax: if (test expression) { true-block statements; } else { false-block statements; } statement – x;
  • 10. “ 10 Flow Chart For If else Statement 10
  • 11.  Here if the code is equal to ‘1’ the statement boy=boy+1; Is executed and the control is transferred to the statement st-n, after skipping the else part. If code is not equal to ‘1’ the statement boy =boy+1; is skipped and the statement in the else part girl =girl+1; is executed before the control reaches the statement st-n. 11 If else Statement Example If (code == 1) boy = boy + 1; else girl = girl + 1; st-x;
  • 12. Nesting of if else statement When a series of decisions are involved we may have to use more than one if-else statement in nested form of follows. Syntax: if ( Test Condition1) { if ( Test Condition2) { Statement -1; } else { Statement -2; } else { Statement -3;} }
  • 13. “ 13 Flow Chart For nesting of If else Statement 13
  • 14. 14 Nesting of If else Statement Example
  • 15. Else-If ladder A multi path decision is charm of its in which the statement associated with each else is an If. It takes the following general form. This construct is known as the wise-If ladder. The conditions are evaluated from the top of the ladder to down wards. As soon as a true condition is found the statement associated with it is executed and the control the is transferred to the st-X (i.e.., skipping the rest of the ladder). when all the n- conditions become false then the final else containing the default – st will be executed.
  • 16. 16 Else-If ladder SYNTAX if (Test Condition -1) { Statement -1; } else if ( Test Condition -2) { Statement -2;} else if ( Test Condition -3) { Statement -3; } else if ( Test Condition –n) { Statement –n; }else { default statement; } Statements-X;
  • 18. “ 18 18 The above construction is known as else if ladders. The conditions are evaluated from top to bottom. As soon as a true condition is found, the statement associated with it is executed and The control is transferred to the Rest of the Program Statement–X (skipping rest of the ladder). When all the “n” conditions become false, then the final else containing the default statement will be executed. Ex : If (code = = 1) Color = “red”; Else if ( code = = 2) Color = “green” Else if (code = = 3) Color = “white”; Else Color = “yellow”; If code number is other than 1,2 and 3 then color is yellow. Else-If ladder