0% found this document useful (0 votes)
22 views11 pages

Topic: Decision Control

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

Topic: Decision Control

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PROBLEM SOLVING TECHNIQUES

Topic : Decision Control


Team Members: Maha Jai Ganesh P S 23BTRE122
Manohara K 23BTRE123
Mohammed Arshat A 23BTRE124
Mohammed Mehrab 23BTRE125
Section:F
FACULTY: MS. TRIVENI N
DESIGNATION: PROFESSOR
INTRODUCTION

In some cases we want to only select statements to be executed. It


allows the programmers to build the programs that determine which
statements of the code should be executed and which should be
ignored.

*C support two types of decision control statements that can alter


the flow of sequence of instructions.

*These include conditional branch statements and unconditional


branch statements
SELECTION/BRANCHING
STATEMENT

CONDITIONAL TYPE UNCONDITIONAL TYPE

IF IF-ELSE IF-ELSE-IF SWITCH


Conditional Branching Statements
*C language possesses such decision making capabilities by supporting
the following statements:
1. If statement
2. If-else statement
3. if-else-if statement
4. else-if ladder statement
5. Switch statement
*These statements are popularly known as decision making
statements. Also known as control statements
1)if statement:
The basic syntax of the "if" statement in C I s as follows:
The general form of simple if statements.

* The Expression is evaluated first, if the value of Expression is true (or non zero) then Statement1 will be
executed; otherwise if it is false (or zero), then Statement1 will be skipped and the execution will jump to the
Statement2.
2)if-else statement:
The "if-else" statement allows you to provide an alternative block of code to be executed when the
condition is false
The if..else statement is an extension of simple if statement.

If the Expression is true (or non-zero) then Statement1 will be executed; otherwise if it is
false (or zero), then Statement2 will be executed.
.
Nested if .. else statement: When a series of decisions are involved, we have to use more than
one if..else statement in nested form as shown below in the general syntax.

If Expression1 is true, check for Expression2, if it is also true then Statement1 is executed.
* If Expression1 is true, check for Expression2, if it is false then Statement2 is executed.
* If Expression1 is false, then Statement3 is executed.
4. else-if ladder or cascaded if else: There is another way of putting ifs together when multipath
decisions are involved. A multi path decision is a chain of ifs in which the statement associated
with each else is an if. It takes the following form

The conditions are evaluated from the top (of the ladder), downwards. As soon as true condition is found, the
statement associated with it is executed and control transferred to the Next statement skipping the rest of the
ladder.
*When all conditions are false then the final else containing the default Statement4 will be executed.
. Switch Statement: C language provides a multi-way decision statement so that complex else-if statements
can be easily replaced by it.
* C languages multi-way decision statement is called switch.

If the choice matches to label1 then block1 will be executed else if it evaluates to label2 then block2 will be
executed and so on.
* If choice does not matches with any case labels, then default block will be executed.
QUIZ

Which keyword is used to initiate an "if"


statement in C?
a. when
b. case
c. if
d. switch
THANK YOU

You might also like