SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Control statements
Topics
 if statement
 switch statement
 goto statement
If statement
 The if statement is a powerful decision
making statement and is used to control the
flow of execution of statements.
 The if statement can be implemented in
different forms:
1. Simple if statement
2. if….else statement
3. Nested if….else statement
4. else if ladder
Simple If statement
 The general form of a simple if statement is:
if(condition)
{
statement-block;
}
satement-x;
 If the condition is true then statement-block
is executed; otherwise the statement-block
will be skipped and the execution will jump
to the statement-x;
If…else statement
 The if…else statement is an extension of the
simple if statement. The general form is
if(condition)
{
True-block statement(s)
}
else
{
False-block statement(s)
}
statement-x;
Continue..
 If the condition is true then the true-block
statement(s) will execute; otherwise the
false-block statement(s) will execute.
 Then it will go to statement-x
 Ex: if(x>y)
z=x-y;
else
z=y-x;
printf(“%d”,z);
Nested If…else statement
 When a series of decisions are involved, we may have to use more than one
if…else statement in nested form as follows:
if(condition-1)
{
if(condition-2)
{
statement-1;
}
else
{
statement-2;
}
}
else
{
statement-3;
}
statement-x;
Continue…
 If condition-1 is false then statement-3 will
be executed; otherwise if continues to
perform the second test.
 If the condition-2 is true, then statement-1
will be executed; otherwise statement-2 will
be executed.
 Then the control will be transferred to
statement-x.
Else If ladder
 There is another way of putting ifs together when
multipath decisions are involved. The general
form:
if(condition-1)
statement-1;
else if(condition-2)
statement-2;
-------------
else if(condition-n)
statement-n;
else
default-statement;
statement-x;
Continue..
 The conditions are evaluated from the top.
As soon as a true condition is found, the
statement associated with it is executed and
the control is transferred to the statement-x.
 When all the conditions are false then the
final else containing the default-statement
will be executed.
switch statement
 Switch is a multiway decision statement. The
general form:
switch(expression)
{
case value-1: block-1;
break;
case value-2: block-2;
break;
-------------
default: default-block;
}
statement-x;
Continue…
 The expression is an integer expression or
character. Value-1, value-2,… are constants or
constant expression and are known as case
labels. Each of these values should be unique.
 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,
the block of statements are executed.
 The break at the end of each block signals the end
of particular case and causes exit from switch and
transfer control to statement-x.
 The default is optional and if no matches occur
then this default-block is executed.

Weitere ähnliche Inhalte

Was ist angesagt?

Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
IF Statement
IF StatementIF Statement
IF StatementYunis20
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ programmatiur rahman
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
While loop
While loopWhile loop
While loopFeras_83
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++Jayant Dalvi
 
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
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 

Was ist angesagt? (20)

Loops in C
Loops in CLoops in C
Loops in C
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
IF Statement
IF StatementIF Statement
IF Statement
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ program
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Java basic introduction
Java basic introductionJava basic introduction
Java basic introduction
 
Control statements
Control statementsControl statements
Control statements
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Inline function
Inline functionInline function
Inline function
 
While loop
While loopWhile loop
While loop
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
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
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Control structure
Control structureControl structure
Control structure
 

Ähnlich wie Chap 5(decision making-branching)

If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
C statements
C statementsC statements
C statementsAhsann111
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional StatementDeepak Singh
 
Decision control structures
Decision control structuresDecision control structures
Decision control structuresRahul Bathri
 
Control structure of c language
Control structure of c languageControl structure of c language
Control structure of c languageDigvijaysinh Gohil
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsMaryamSohail4
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
Decision makingandbranching in c
Decision makingandbranching in cDecision makingandbranching in c
Decision makingandbranching in cNMahendiran
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)TejaswiB4
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
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
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 

Ähnlich wie Chap 5(decision making-branching) (20)

If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
C statements
C statementsC statements
C statements
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional Statement
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
 
Control structure of c language
Control structure of c languageControl structure of c language
Control structure of c language
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Decision makingandbranching in c
Decision makingandbranching in cDecision makingandbranching in c
Decision makingandbranching in c
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
Decision Making.pptx
Decision Making.pptxDecision Making.pptx
Decision Making.pptx
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
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
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 

Mehr von Bangabandhu Sheikh Mujibur Rahman Science and Technology University

Mehr von Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Antenna (2)
Antenna (2)Antenna (2)
Antenna (2)
 
Voltage suppler..
Voltage suppler..Voltage suppler..
Voltage suppler..
 
Number system
Number systemNumber system
Number system
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
Computer hardware ppt1
 
# Operating system
# Operating system# Operating system
# Operating system
 
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 3
 
Magnetism 2
Magnetism 2Magnetism 2
Magnetism 2
 
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
2. sinusoidal waves
 
Magnetism 1
Magnetism 1Magnetism 1
Magnetism 1
 

Kürzlich hochgeladen

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Kürzlich hochgeladen (20)

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Chap 5(decision making-branching)

  • 1. Control statements Topics  if statement  switch statement  goto statement
  • 2. If statement  The if statement is a powerful decision making statement and is used to control the flow of execution of statements.  The if statement can be implemented in different forms: 1. Simple if statement 2. if….else statement 3. Nested if….else statement 4. else if ladder
  • 3. Simple If statement  The general form of a simple if statement is: if(condition) { statement-block; } satement-x;  If the condition is true then statement-block is executed; otherwise the statement-block will be skipped and the execution will jump to the statement-x;
  • 4. If…else statement  The if…else statement is an extension of the simple if statement. The general form is if(condition) { True-block statement(s) } else { False-block statement(s) } statement-x;
  • 5. Continue..  If the condition is true then the true-block statement(s) will execute; otherwise the false-block statement(s) will execute.  Then it will go to statement-x  Ex: if(x>y) z=x-y; else z=y-x; printf(“%d”,z);
  • 6. Nested If…else statement  When a series of decisions are involved, we may have to use more than one if…else statement in nested form as follows: if(condition-1) { if(condition-2) { statement-1; } else { statement-2; } } else { statement-3; } statement-x;
  • 7. Continue…  If condition-1 is false then statement-3 will be executed; otherwise if continues to perform the second test.  If the condition-2 is true, then statement-1 will be executed; otherwise statement-2 will be executed.  Then the control will be transferred to statement-x.
  • 8. Else If ladder  There is another way of putting ifs together when multipath decisions are involved. The general form: if(condition-1) statement-1; else if(condition-2) statement-2; ------------- else if(condition-n) statement-n; else default-statement; statement-x;
  • 9. Continue..  The conditions are evaluated from the top. As soon as a true condition is found, the statement associated with it is executed and the control is transferred to the statement-x.  When all the conditions are false then the final else containing the default-statement will be executed.
  • 10. switch statement  Switch is a multiway decision statement. The general form: switch(expression) { case value-1: block-1; break; case value-2: block-2; break; ------------- default: default-block; } statement-x;
  • 11. Continue…  The expression is an integer expression or character. Value-1, value-2,… are constants or constant expression and are known as case labels. Each of these values should be unique.  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, the block of statements are executed.  The break at the end of each block signals the end of particular case and causes exit from switch and transfer control to statement-x.  The default is optional and if no matches occur then this default-block is executed.