Page 78 - TechPluse_C4_Flipbook
P. 78
Step 12 Drag to the slot to set value of Quotient.
Step 13 Drag the variable blocks of N1 and N2 to fit in the slots 1 and 2 respectively of the
division block.
Step 14 Click on the Flag button to run the program.
Output of the division
CONDITIONS
Sometimes, the flow of the program may not be in a sequence. There are situations when the
control of the program has to be transferred to a different set of instructions upon a condition
becoming true or false. When the condition is to be checked, it is called taking a decision. The
statements that are executed on the basis of decisions taken from a choice are called conditional
statements.
The conditional statement used in Scratch is the ‘if’ statement. The ‘if’ statement has two variants
—‘if…then’ and ‘if…then…else’. These statements are provided in Scratch from control category of
blocks. The ‘if…then’ block checks the given condition. If the condition is true, the code inside the
C (space) will be activated. If the condition is false, the control will come out of the ‘if…then’ block
and move to the next blocks in the sequence.
Suppose, we want to check whether a person is a senior citizen or
not. The code for this can be defined using ‘if’…then’ as:
But this code does not give an output if the
age of the person is less than or equal to 60
years.
For such situations, when two different outputs
are to be specified for two conditions, we use ‘if…then…else’ block. In
this block, if the condition is true, the code inside the first C (space)
will be activated. If the condition is false, the code inside the second C
(space) will be activated.
76 Premium Edition-IV

