[go: up one dir, main page]

0% found this document useful (0 votes)
7 views13 pages

Desicion Making Statements

Uploaded by

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

Desicion Making Statements

Uploaded by

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

DECISION STATEMENT

DECISION / CONTROL STATEMENT : Decision making statements are used to execute a set
of instructions or skip the instructions based on certain condition.

Decision statement helps the programmer to skip the block of instructions from the execution if
the condition is not satisfied.

TYPES OF DECISION STATEMENT :


I. if statement
II. if-else statement
III. if-else if ladder
IV. Nested if
V. switch
IF STATEMENT
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 i.e if a certain condition is true then a block
of statements is executed otherwise not.

Syntax to create if statement :

true If
if (condition) condition
?

{ false
statement
}

WORK FLOW :
If the condition is satisfied then the instruction written inside the if block gets
executed or normal flow of the execution continues(Instructions written inside the if
block is skipped).
IF-ELSE STATEMENT
The if statement alone tells us that if a condition is true it will execute a block of statements and if the
condition is false it won’t. But what if we want to do something else if the condition is false? Here comes
the else statement. We can use the else statement with the if statement to execute a block of code
when the condition is false.
Syntax to create if-else statement :

if (condition)
true If false
{ condition
?

} Statement 1 else block


else
{

WORKFLOW :
If the condition is satisfied then the instruction written inside the if block gets
executed if not satisfied else block gets executed (any one of the block will be skipped
depending on the condition.)
IF-ELSE IF STATEMENT
Here, a user can decide among multiple options.The if statements are executed from the top down. As
soon as one of the conditions controlling the if is true, the statement associated with that ‘if’ is executed,
and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will
be executed. There can be as many as ‘else if’ blocks associated with one ‘if’ block but only one ‘else’ block
is allowed with one ‘if’ block.
Syntax to create if-else if statement :
if (condition)
{

}
else if (condition)
{

}
else if (condition)
{

}
.
.
else
{

WORK FLOW :
If the condition is satisfied then the instruction written inside the if block gets executed if not
satisfied, condition is checked in the else if block from top to bottom order and if the condition is satisfied in
any of the else if block then , only that else if block is gets executed if not satisfied else block gets executed
remaining blocks are skipped
true if false
condition
?

true else if false


Statement 1 condition
?

Statement 2 true else if false


condition
?

true else if
condition
false
Statement 3 ?

Statement 4
else block
NESTED-IF
Nested if statements mean an if statement inside an if statement.
SWITCH STATEMENT
Syntax to create switch block
switch(value / variable /
expression )
{
The switch statement is a multiway
case value / expression :
{
branch statement. It provides an easy
}
statement; way to dispatch execution to different
[break ;] parts of code based on the value of the
case value / expression :
{
expression.
statement;
}
[break ;]
.
.
.

default :
{
statement ;
}
[break ;]
}
WORKFLOW :
• The value / variable / expression passed in the switch gets compared with value
passed in the case from top to bottom order.
• If any of a case is satisfied , the case block is executed and all the blocks present
below gets executed.
• If no case is satisfied then default block gets executed.
• For a case we can use a break statement which is optional.
NOTE :
• For a switch we can’t pass long , float , double , boolean.
• For a case we can’t pass variable.
BREAK :
• break is a keyword , it is a control transfer statement.
• break is used inside the switch and loop block
• When the break statement is executed control is transferred outside the block.

You might also like