Page 46 - Touchcode_C8_Flipbook
P. 46
RETURNING VALUE FROM A FUNCTION
The main purpose of using functions is to get rid of the repetitive block of code. So, when
an operation is performed inside a function it gives back a value, which can be used later in
the program to get the results, which makes a function more useful.
Consider an example of, Coding task 01, in this task, you have calculated the volume of a
cuboid, the VolumeofCuboid did not return any value. But when the program executes, the
volume of cuboid gets calculated and assigned the variable “volume” to it, then it returns a
value. However, it becomes useless if the function doesn’t return.
This can be understood as, your mother prepares your favorite food for your lunch to have
in the school during recess time, but you forget your lunch at home. So that prepared food
is of no use to you as you have forgot to take your lunch. Returning a value is getting the
lunch prepared by your mother for school to eat.
To implement return function in coding task 01, follow these steps:
Step 1: The code for calculating the volume of cuboid is:
Step 2: Click on the ‘Functions’, select ‘return’ block. Drag and replace it with ‘splash’
volume block in the function block and add the variable ‘volume’ to its text area
as shown below:
44 Touchcode-VIII

