SlideShare a Scribd company logo
1 of 23
Presented By,
SWASTIKA TRIPATHI
 Repeating important sections of the program.
 Selecting between optional section of a program
Decision
Making
Statement
Decision
Making and
Branching
IF Statement
SWITCH
Statement
Conditional
Operator
Statement
GOTO
Statement
Decision
Making and
Looping
The WHILE
Loop
The do-while
Loop
The FOR
Loop
• DECISION MAKING AND BRANCHING
 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.
• DECISION MAKING AND LOOPING
 Execution of the statement or set of statement repeatedly is
known as LOOPING.
 This may be executed a specified number of times and this
depends on the satisfaction of a test condition.
 A program loop is made up of two parts one part is known as
body of the loop and the other is known as control condition.
 Depending on the control condition statement , the statements
within the loop may be executed.
 The IF statement is the powerful decision making
statement and is used to control the flow of execution of
the statements.
 When decision making in a program they are simply the
result of computation in which the final result is either
TRUE or FALSE.
 The value zero (0) is considered to be FALSE in program.
Any positive or negative value is considered to be TRUE.
Levels of complexity for IF:
1.Simple IF statement
2.IF…..ELSE statement
3.NESTED IF…..ELSE statement
4.ELSE…..IF ladder
It is used to control the flow of execution of the
statements and also to test logically whether the
condition is true or false.
Syntax:
if (condition)
{
statement ;
}
If the condition is true then the statement following
the “if” is executed if it is false then the statement is
skipped.
( Flow chart of Simple if statement )
Test
Condition
Executable X - Statement
TRUE
The if…..else statement is an extension of the simple if
statement.
Syntax:
if (condition)
{
statement 1; (if the condition is TRUE this statement will be executed)
}
else
{
statement 2; (if the condition is FALSE this statement will be executed)
}
It is used to execute some statements when the
condition is true and execute some other statements
when the condition is false depending on the logical
test.
( Flow chart of if…..else statement )
Test
Condition
Executable X - StatementExecutable Y - Statement
TRUEFALSE
 When a series of if…..else statements are occurred in a program, we can write
an entire if…..else statement in another if…..else statement called NESTING.
Syntax:
If (condition 1)
{
if (condition 2)
{
statement 1;
}
else
{
statement 2;
}
}
else
{
if (condition 3)
statement 3;
else
statement 4;
}
Test
Condition-1
Test
Condition-1
Statement-2 Statement-3
Statement-3 Statement-4
( Flow chart of nested if……else
statement )
TRUE
TRUE
FALSE
FALSE
Test
Condition-3
FALSE TRUE
When a series of decisions are involved we have to use more than one
if…..else statement called as multiple if’s. Multiple if…..else statements
are much faster than a series of if…..else statements, since their
structure when any of the condition is satisfied.
Syntax:
if (condition 1)
statement 1;
else if (condition 2)
statement 2;
else if (condition 3)
statement 3;
----------------
----------------
else if (condition n)
statement n;
else
statement x;
( Flow chart of else…..if ladder )
Test
Condition 1
Statement 1
TRUE
Test
Condition
3
FALSE
Statement 2
TRUETest
Condition 2
TRUE
Statement 2
FALSE
FALSE
Test
Condition
n
Statement n
Statement X
TRUE
FALSE
 The control statement which allows us to make decision from
the number of choices is called switch or switch case
statement.
 It is a multi way decision statement, it test the given variable
or expression against a list of case values.
switch (expression)
{
case constant 1:
block 1
break;
case constant 2:
block 2
break;
----------
----------
default:
default block
break;
}
Statement –x;
(Selection process of the SWITCH Statemen
Switch
expression
Block-1
Block-2
default
block
Statement-x
Expression = value -1
Expression = value -2
(no match) default
 This operator is a combination of ? And : , and takes
three operands.
 General form:
conditional expression ? exp-1:exp-2;
 This concept says that if this expression is true then
whatever we are writing after this question mark
statement, it will be executed.
And if this expression is false then whatever
we are writing after this colon statement, it will be
executed.
 Like many other languages, C supports the GOTO
statement to branch unconditionally from one point to
another in the program.
 Although it may not be essential to use the GOTO
statement in a Highly Structured Language.
 General form:
 Not recommended but may be used occasionally.
goto label;
……….
……….
……….
label:
statement;
 A WHILE loop has one control expression, and
executes as long as that expression is true.
 A WHILE loop is an entry controlled loop.
Syntax:
While (condition)
{
statement (s);
increment or decrement loop counter
}
Start
Initialize
Test
Condition
Stop
Body of Loop
Increment or Decrement
FALSE
TRUE
Flow chart of WHILE
 The body of the loop may not be executed if the condition is not
satisfied in while loop.
 Since the test is done at the end of the loop, the statement in the
braces will always be executed at least once.
 The statements in the braces are executed repeatedly as long as
the expression in the parentheses is true.
Make a note that do while loop ends in a ; (semicolon)
Note that Do…..While Looping Statement is Exit Controlled
Looping Statement.
Syntax:
initialize loop counter;
Do
{
statement (s);
increment or decrement loop counter
}
While (condition);
Start
Initialize
Test
Condition
Body of Loop
Increment or Decrement
FALSE
TRUE
Stop
Flow chart of
do-while
LOOP
 The for loop is another repetitive control structure, and is
used to execute set of instruction repeatedly until the
condition becomes false.
 To set up an initial condition and then modify some value to
perform each succeeding loop as long as some condition is
true.
 The three expressions:
expr1 – sets up the initial condition,
expr2 – tests whether another trip through the loop should
be taken,
expr3 – increments or updates thing after each trip.
Syntax:
for(expr1; expr2; expr3)
{
body of the loop;
}
Start
Body of Loop
Stop
Initialize; test condition; Increment / Decrement
Flow chart of for
Decision Making Statement in C ppt

More Related Content

What's hot

C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 

What's hot (20)

C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
C if else
C if elseC if else
C if else
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Strings
StringsStrings
Strings
 
Looping statement
Looping statementLooping statement
Looping statement
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 

Similar to Decision Making Statement in C ppt

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
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)TejaswiB4
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 
Diploma ii cfpc u-3 handling input output and control statements
Diploma ii  cfpc u-3 handling input output and control statementsDiploma ii  cfpc u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statementsRai University
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsRai University
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsRai University
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statementsRai University
 
Bsc cs pic u-3 handling input output and control statements
Bsc cs  pic u-3 handling input output and control statementsBsc cs  pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statementsRai University
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structuresayshasafdarwaada
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, LoopingMURALIDHAR R
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxSKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxLECO9
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition StructureShahzu2
 
Control Structures Python like conditions and loops
Control Structures Python like conditions and loopsControl Structures Python like conditions and loops
Control Structures Python like conditions and loopsramireddyobulakondar
 

Similar to Decision Making Statement in C ppt (20)

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
 
CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Control statements
Control statementsControl statements
Control statements
 
Diploma ii cfpc u-3 handling input output and control statements
Diploma ii  cfpc u-3 handling input output and control statementsDiploma ii  cfpc u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
 
Bsc cs pic u-3 handling input output and control statements
Bsc cs  pic u-3 handling input output and control statementsBsc cs  pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Control Structures Python like conditions and loops
Control Structures Python like conditions and loopsControl Structures Python like conditions and loops
Control Structures Python like conditions and loops
 

Recently uploaded

School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 

Recently uploaded (20)

School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 

Decision Making Statement in C ppt

  • 2.  Repeating important sections of the program.  Selecting between optional section of a program Decision Making Statement Decision Making and Branching IF Statement SWITCH Statement Conditional Operator Statement GOTO Statement Decision Making and Looping The WHILE Loop The do-while Loop The FOR Loop
  • 3. • DECISION MAKING AND BRANCHING  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. • DECISION MAKING AND LOOPING  Execution of the statement or set of statement repeatedly is known as LOOPING.  This may be executed a specified number of times and this depends on the satisfaction of a test condition.  A program loop is made up of two parts one part is known as body of the loop and the other is known as control condition.  Depending on the control condition statement , the statements within the loop may be executed.
  • 4.  The IF statement is the powerful decision making statement and is used to control the flow of execution of the statements.  When decision making in a program they are simply the result of computation in which the final result is either TRUE or FALSE.  The value zero (0) is considered to be FALSE in program. Any positive or negative value is considered to be TRUE. Levels of complexity for IF: 1.Simple IF statement 2.IF…..ELSE statement 3.NESTED IF…..ELSE statement 4.ELSE…..IF ladder
  • 5. It is used to control the flow of execution of the statements and also to test logically whether the condition is true or false. Syntax: if (condition) { statement ; }
  • 6. If the condition is true then the statement following the “if” is executed if it is false then the statement is skipped. ( Flow chart of Simple if statement ) Test Condition Executable X - Statement TRUE
  • 7. The if…..else statement is an extension of the simple if statement. Syntax: if (condition) { statement 1; (if the condition is TRUE this statement will be executed) } else { statement 2; (if the condition is FALSE this statement will be executed) }
  • 8. It is used to execute some statements when the condition is true and execute some other statements when the condition is false depending on the logical test. ( Flow chart of if…..else statement ) Test Condition Executable X - StatementExecutable Y - Statement TRUEFALSE
  • 9.  When a series of if…..else statements are occurred in a program, we can write an entire if…..else statement in another if…..else statement called NESTING. Syntax: If (condition 1) { if (condition 2) { statement 1; } else { statement 2; } } else { if (condition 3) statement 3; else statement 4; }
  • 10. Test Condition-1 Test Condition-1 Statement-2 Statement-3 Statement-3 Statement-4 ( Flow chart of nested if……else statement ) TRUE TRUE FALSE FALSE Test Condition-3 FALSE TRUE
  • 11. When a series of decisions are involved we have to use more than one if…..else statement called as multiple if’s. Multiple if…..else statements are much faster than a series of if…..else statements, since their structure when any of the condition is satisfied. Syntax: if (condition 1) statement 1; else if (condition 2) statement 2; else if (condition 3) statement 3; ---------------- ---------------- else if (condition n) statement n; else statement x;
  • 12. ( Flow chart of else…..if ladder ) Test Condition 1 Statement 1 TRUE Test Condition 3 FALSE Statement 2 TRUETest Condition 2 TRUE Statement 2 FALSE FALSE Test Condition n Statement n Statement X TRUE FALSE
  • 13.  The control statement which allows us to make decision from the number of choices is called switch or switch case statement.  It is a multi way decision statement, it test the given variable or expression against a list of case values. switch (expression) { case constant 1: block 1 break; case constant 2: block 2 break; ---------- ---------- default: default block break; } Statement –x;
  • 14. (Selection process of the SWITCH Statemen Switch expression Block-1 Block-2 default block Statement-x Expression = value -1 Expression = value -2 (no match) default
  • 15.  This operator is a combination of ? And : , and takes three operands.  General form: conditional expression ? exp-1:exp-2;  This concept says that if this expression is true then whatever we are writing after this question mark statement, it will be executed. And if this expression is false then whatever we are writing after this colon statement, it will be executed.
  • 16.  Like many other languages, C supports the GOTO statement to branch unconditionally from one point to another in the program.  Although it may not be essential to use the GOTO statement in a Highly Structured Language.  General form:  Not recommended but may be used occasionally. goto label; ………. ………. ………. label: statement;
  • 17.  A WHILE loop has one control expression, and executes as long as that expression is true.  A WHILE loop is an entry controlled loop. Syntax: While (condition) { statement (s); increment or decrement loop counter }
  • 18. Start Initialize Test Condition Stop Body of Loop Increment or Decrement FALSE TRUE Flow chart of WHILE
  • 19.  The body of the loop may not be executed if the condition is not satisfied in while loop.  Since the test is done at the end of the loop, the statement in the braces will always be executed at least once.  The statements in the braces are executed repeatedly as long as the expression in the parentheses is true. Make a note that do while loop ends in a ; (semicolon) Note that Do…..While Looping Statement is Exit Controlled Looping Statement. Syntax: initialize loop counter; Do { statement (s); increment or decrement loop counter } While (condition);
  • 20. Start Initialize Test Condition Body of Loop Increment or Decrement FALSE TRUE Stop Flow chart of do-while LOOP
  • 21.  The for loop is another repetitive control structure, and is used to execute set of instruction repeatedly until the condition becomes false.  To set up an initial condition and then modify some value to perform each succeeding loop as long as some condition is true.  The three expressions: expr1 – sets up the initial condition, expr2 – tests whether another trip through the loop should be taken, expr3 – increments or updates thing after each trip. Syntax: for(expr1; expr2; expr3) { body of the loop; }
  • 22. Start Body of Loop Stop Initialize; test condition; Increment / Decrement Flow chart of for