SlideShare a Scribd company logo
Decision Making and Branching in C
SUMAN AGGARWAL
ASSISTANT PROFESSOR
ADVANCED EDUCATIONAL INSTITUTE
www.advanced.edu.in
In programming the order of execution of instructions may have to be changed depending on
certain conditions. This involves a kind of decision making to see whether a particular condition
has occurred or not and then direct the computer to execute certain instructions accordingly
C language posses such decision making capabalities by supporting the following ststement:
1. if statement
2. Nesting of if else Statement
3. switch statement
4. goto statement
www.advanced.edu.in
Decision making with if statement
The if statement is a powerful decision making statement and is used to control the flow of
execution of statements.
The syntax is
if (expression)
The expression is evaluated and depending on whether the value of the expression is true (non
zero) or false (zero) it transfers the control to a particular statement
www.advanced.edu.in
The general form of simple if
statement is:
if (test expression)
{
statement block;
}
statement n;
www.advanced.edu.in
Small Description
www.advanced.edu.in
Syntax is:
if (test expression)
{
statement block;
}
else
{
statement block;
}
statement n;
Nesting of if....else statement:
www.advanced.edu.in
When a series of conditions are to be checked, we may have to use more than one if... else
statement in the nested form.
if (test condition 1)
{
if (test condition 2)
{
statement block 1;
}
else
{
statement block 2;
} statement m;
}
else
{
if (test condition 3)
{
statement block 3;
}
else
{
statement block 4
} statement n;
}
statement x; -
Description of if....else statement:
If the test condition 1 is true then, test condition 2 is checked and if it is true, then the statement
block 1 will be executed and the control will be transferred to statement m and it will executed
and then statement x will be executed.
If the test condition 1 is true but test condition 2 is false, statement block 2 will be executed and
the control is transferred to statement m and it will be executed and then statement x will be
executed.
If the test condition 1 is false, then test condition 3 is checked and if it is true, statement block 3
will be executed, then control is transferred to statement n and it will be executed and then
statement x will be executed.
If the test condition 1 is false and test condition 3 is also false, statement block 4 will be
executed, then the control is transferred to statement n and it will be executed and then statement
x is executed.
-
www.advanced.edu.in
Switch Statement
www.advanced.edu.in
The switch structure is a multiple-selection structure that
allows even more complicated decision statements than a two-
way if/else structure allows.
It chooses one of the "cases" depending on the result of the
control expression.
Only variables with the INT or CHAR data types may be used in
the control expressions (i.e. parentheses) of switch statements.
Single quotes must be used around CHAR variables
Single quotes are NOT used around the integer value
Switch Syntax
www.advanced.edu.in
switch (expression)
{
case value 1 :
statement block 1;
break;
case value 2:
statement block 2;
break;
:
:
default:
default block;
}
statement n;
Flowchart Switch Statement
www.advanced.edu.in
Description Switch Statement
www.advanced.edu.in
The expression is an integer expression or characters. Value 1, value 2, ...... are constants , constant
expressions (evaluable to an integral constant) or character and are known as case labels. Each of these
values should be unique within a switch statement, statement block 1, statement block 2, ........ are
statement list and may contain 0 or more statements. There is no need to put braces between these
blocks. The case labels end with a colon (:).
When the switch is executed, the value of the expression is successively compared against the values
value 1, value 2, ...... If a case is found whose value matches with the value of the expression, then the
block of statement that follows that case are executed. The break statement at the end of each block,
signals the end of a particular case and causes an exit from the switch statement transferring the control
to the statement n following the switch block. The default is an optional case. When present, it will be
executed if the value of the expression does not match with any of the case values and then the statement
n will be executed. If not present no action takes place if all matches fails and the control goes to
statement n.
The goto statement
www.advanced.edu.in
This statement is used to branch unconditionally from one point to another in the
program. This statement goto requires a label to locate the place where the branch is to
be made. A label is any valid identifier and must be followed by a colon. The label is
placed immediately before the statement where the control is to be transferred.
Different ways of using goto statement are given below:
Syntax:
goto label;
Forward jump
www.advanced.edu.in
•Forward jump: In this the position of the label is after the goto statement.
goto label;
:
:
label:
statement n;
Example:
goto read;
n = 5 * 4;
:
:
read:
scanf ("%d", &code);
•:
:
Backward jump
www.advanced.edu.in
Backward jump: In this, the position of the label is before the goto statement
label:
statement n;
: goto label;
Example:
. . read:
scanf ("%d", &code);
:
:
goto read;
n = 5 * 4;
:
:
Conclusion
www.advanced.edu.in
The C language programs presented until now follows a sequential form of execution of
statements. Many times it is required to alter the flow of the sequence of instructions. C language
provides statements that can alter the flow of a sequence of instructions. These statements are
called control statements. These statements help to jump from one part of the program to another.
The control transfer may be conditional or unconditional.
Suman Aggarwal
Assistant Professor
Advanced Educational Institutions
◦ Advanced Educational Institutions,
◦ 70 km Milestone,
◦ Delhi-Mathura Road, Dist. Palwal, Haryana-121105
◦ +91–1275–398400, 302222
Contact Email Id: sumanaggrawal@gmail.com
Website: http://www.advanced.edu.in
www.advanced.edu.in
“THANK YOU”

More Related Content

PPTX
Selection statements
PPTX
Selection Statements in C Programming
PPT
Mesics lecture 6 control statement = if -else if__else
PPT
Decision Making and Branching in C
PPTX
Switch statement, break statement, go to statement
PDF
C programming decision making
PPT
Control statements and functions in c
Selection statements
Selection Statements in C Programming
Mesics lecture 6 control statement = if -else if__else
Decision Making and Branching in C
Switch statement, break statement, go to statement
C programming decision making
Control statements and functions in c

What's hot (20)

PPT
Decision making and branching
PPTX
C# conditional branching statement
PPT
If-else and switch-case
PPSX
Conditional statement
PPTX
Decision Making Statement in C ppt
PPTX
Control statement-Selective
PPTX
Decision control structures
PPT
Control Structure in C
PPT
Branching in C
PPTX
Flow of control by deepak lakhlan
PPTX
Decision making and branching in c programming
PPTX
Control Statement programming
PDF
Control statement
PPT
Flow of Control
PDF
nuts and bolts of c++
PPT
Control Structures
PPT
The Three Basic Selection Structures in C++ Programming Concepts
PPTX
Switch Case in C Programming
PDF
10. switch case
Decision making and branching
C# conditional branching statement
If-else and switch-case
Conditional statement
Decision Making Statement in C ppt
Control statement-Selective
Decision control structures
Control Structure in C
Branching in C
Flow of control by deepak lakhlan
Decision making and branching in c programming
Control Statement programming
Control statement
Flow of Control
nuts and bolts of c++
Control Structures
The Three Basic Selection Structures in C++ Programming Concepts
Switch Case in C Programming
10. switch case
Ad

Viewers also liked (20)

PDF
Branching in PowerPoint
PPTX
C decision making and looping.
PPT
Decision making and looping
PPTX
Loops in C
PDF
itft-Decision making and branching in java
PPT
Tokens_C
PPT
Token system powerpoint
PPT
Types of operators in C
PDF
Lecture13 control statementswitch.ppt
PPT
Prsentation on functions
PPTX
C tokens
PPTX
C programing -Structure
PPTX
Switch case and looping
PPTX
Functions in C
PPTX
Functions in C
PPTX
C programming-apurbo datta
PPTX
Function in c
PDF
Function in C
PPTX
Flowchart and algorithm
PPTX
Loops in C Programming
Branching in PowerPoint
C decision making and looping.
Decision making and looping
Loops in C
itft-Decision making and branching in java
Tokens_C
Token system powerpoint
Types of operators in C
Lecture13 control statementswitch.ppt
Prsentation on functions
C tokens
C programing -Structure
Switch case and looping
Functions in C
Functions in C
C programming-apurbo datta
Function in c
Function in C
Flowchart and algorithm
Loops in C Programming
Ad

Similar to C language control statements (20)

PPTX
Decision makingandbranching in c
PPTX
Conditional statement in c
PDF
controlflowwSoftware Development Fundamentals (SDF) – I ODD 2024 Jaypee Insti...
PPT
Decision making in C(2020-2021) statements
PPTX
DECISION MAKING AND BRANCHING - C Programming
PPT
Final requirement
PPTX
Decision statements in c language
PPTX
Decision statements in c laguage
PPTX
Presentation on C Switch Case Statements
PDF
Lecture 7 Control Statements.pdf
PDF
1. Control Structure in C.pdf
DOCX
Chapter 4(1)
PPTX
Basics of Control Statement in C Languages
PPT
C statements.ppt presentation in c language
PPT
Switch statements in Java
PDF
Unit ii chapter 2 Decision making and Branching in C
PPTX
Cse lecture-6-c control statement
PPTX
Programming Fundamentals lec 08 .pptx
Decision makingandbranching in c
Conditional statement in c
controlflowwSoftware Development Fundamentals (SDF) – I ODD 2024 Jaypee Insti...
Decision making in C(2020-2021) statements
DECISION MAKING AND BRANCHING - C Programming
Final requirement
Decision statements in c language
Decision statements in c laguage
Presentation on C Switch Case Statements
Lecture 7 Control Statements.pdf
1. Control Structure in C.pdf
Chapter 4(1)
Basics of Control Statement in C Languages
C statements.ppt presentation in c language
Switch statements in Java
Unit ii chapter 2 Decision making and Branching in C
Cse lecture-6-c control statement
Programming Fundamentals lec 08 .pptx

Recently uploaded (20)

PPTX
Construction Project Organization Group 2.pptx
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Current and future trends in Computer Vision.pptx
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Artificial Intelligence
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
Construction Project Organization Group 2.pptx
Categorization of Factors Affecting Classification Algorithms Selection
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
UNIT 4 Total Quality Management .pptx
Current and future trends in Computer Vision.pptx
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
573137875-Attendance-Management-System-original
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Internet of Things (IOT) - A guide to understanding
Artificial Intelligence
Safety Seminar civil to be ensured for safe working.
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Automation-in-Manufacturing-Chapter-Introduction.pdf

C language control statements

  • 1. Decision Making and Branching in C SUMAN AGGARWAL ASSISTANT PROFESSOR ADVANCED EDUCATIONAL INSTITUTE www.advanced.edu.in
  • 2. In programming the order of execution of instructions may have to be changed depending on certain conditions. This involves a kind of decision making to see whether a particular condition has occurred or not and then direct the computer to execute certain instructions accordingly C language posses such decision making capabalities by supporting the following ststement: 1. if statement 2. Nesting of if else Statement 3. switch statement 4. goto statement www.advanced.edu.in
  • 3. Decision making with if statement The if statement is a powerful decision making statement and is used to control the flow of execution of statements. The syntax is if (expression) The expression is evaluated and depending on whether the value of the expression is true (non zero) or false (zero) it transfers the control to a particular statement www.advanced.edu.in
  • 4. The general form of simple if statement is: if (test expression) { statement block; } statement n; www.advanced.edu.in
  • 5. Small Description www.advanced.edu.in Syntax is: if (test expression) { statement block; } else { statement block; } statement n;
  • 6. Nesting of if....else statement: www.advanced.edu.in When a series of conditions are to be checked, we may have to use more than one if... else statement in the nested form. if (test condition 1) { if (test condition 2) { statement block 1; } else { statement block 2; } statement m; } else { if (test condition 3) { statement block 3; } else { statement block 4 } statement n; } statement x; -
  • 7. Description of if....else statement: If the test condition 1 is true then, test condition 2 is checked and if it is true, then the statement block 1 will be executed and the control will be transferred to statement m and it will executed and then statement x will be executed. If the test condition 1 is true but test condition 2 is false, statement block 2 will be executed and the control is transferred to statement m and it will be executed and then statement x will be executed. If the test condition 1 is false, then test condition 3 is checked and if it is true, statement block 3 will be executed, then control is transferred to statement n and it will be executed and then statement x will be executed. If the test condition 1 is false and test condition 3 is also false, statement block 4 will be executed, then the control is transferred to statement n and it will be executed and then statement x is executed. - www.advanced.edu.in
  • 8. Switch Statement www.advanced.edu.in The switch structure is a multiple-selection structure that allows even more complicated decision statements than a two- way if/else structure allows. It chooses one of the "cases" depending on the result of the control expression. Only variables with the INT or CHAR data types may be used in the control expressions (i.e. parentheses) of switch statements. Single quotes must be used around CHAR variables Single quotes are NOT used around the integer value
  • 9. Switch Syntax www.advanced.edu.in switch (expression) { case value 1 : statement block 1; break; case value 2: statement block 2; break; : : default: default block; } statement n;
  • 11. Description Switch Statement www.advanced.edu.in The expression is an integer expression or characters. Value 1, value 2, ...... are constants , constant expressions (evaluable to an integral constant) or character and are known as case labels. Each of these values should be unique within a switch statement, statement block 1, statement block 2, ........ are statement list and may contain 0 or more statements. There is no need to put braces between these blocks. The case labels end with a colon (:). When the switch is executed, the value of the expression is successively compared against the values value 1, value 2, ...... If a case is found whose value matches with the value of the expression, then the block of statement that follows that case are executed. The break statement at the end of each block, signals the end of a particular case and causes an exit from the switch statement transferring the control to the statement n following the switch block. The default is an optional case. When present, it will be executed if the value of the expression does not match with any of the case values and then the statement n will be executed. If not present no action takes place if all matches fails and the control goes to statement n.
  • 12. The goto statement www.advanced.edu.in This statement is used to branch unconditionally from one point to another in the program. This statement goto requires a label to locate the place where the branch is to be made. A label is any valid identifier and must be followed by a colon. The label is placed immediately before the statement where the control is to be transferred. Different ways of using goto statement are given below: Syntax: goto label;
  • 13. Forward jump www.advanced.edu.in •Forward jump: In this the position of the label is after the goto statement. goto label; : : label: statement n; Example: goto read; n = 5 * 4; : : read: scanf ("%d", &code); •: :
  • 14. Backward jump www.advanced.edu.in Backward jump: In this, the position of the label is before the goto statement label: statement n; : goto label; Example: . . read: scanf ("%d", &code); : : goto read; n = 5 * 4; : :
  • 15. Conclusion www.advanced.edu.in The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the flow of the sequence of instructions. C language provides statements that can alter the flow of a sequence of instructions. These statements are called control statements. These statements help to jump from one part of the program to another. The control transfer may be conditional or unconditional.
  • 16. Suman Aggarwal Assistant Professor Advanced Educational Institutions ◦ Advanced Educational Institutions, ◦ 70 km Milestone, ◦ Delhi-Mathura Road, Dist. Palwal, Haryana-121105 ◦ +91–1275–398400, 302222 Contact Email Id: [email protected] Website: http://www.advanced.edu.in www.advanced.edu.in “THANK YOU”