DECISION MAKING -
BRANCHING
1/77
SELECTION STRUCTURE: IF-
ELSE IF LADDER
• if-else-if ladder helps user decide from
among multiple options.
• 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 else-if ladder
is bypassed.
• If none of the conditions is true, then the final
else statement will be executed.
SELECTION STRUCTURE: IF-
ELSE IF LADDER
FLOWCHART
EXAMPLE 1
EXAMPLE 2
Today is Ram’s birthday and he is looking forward to his
gift. As usual, the gift is hidden and Ram has to follow a
sequence of 5 instructions to reach it.Initially, Ram is
standing in the cell (0,0) of a two-dimensional grid. If we
denote Ram’s current cell by (x, y), each instruction can be
as follows:
'L' means to go left, i.e. to the cell (x,y-1)
'R' means to go right, i.e. to the cell (x,y+1)
'U' means to go up, i.e. to the cell (x-1,y)
'D' means to go down, i.e. to the cell (x+1,y)
Find the cell (xg,yg) which contains the hidden gift.
MCQS
}
Answer:b=300 c=200
Answer: x=10 y=10
Answer: Until my evil purse was filled
Answer:200
Answer:Pilots are on strike
Answer: Error –Expected ‘(‘ before x
Answer: j=0
Answer: Stoned(binary equivalents will be
different)
Answer: x and y are equal
Comparing a float with integer is internally taken to be
comparison between two floats (int will be casted to
float)