Page 63 - Computer Genius Class 07
P. 63
You can make a function named VolumeOfCuboid which takes parameters L, B and H. Now the
function will look like:
VolumeOfCuboid (L, B, H)
{
return L * B * H
}
You only need to provide the value of:
Length (L)
Breadth (B)
Height (H)
Thus the aria les accepted y a unction to per orm the set o tas s defined in its ody are called
function parameters.
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 the previous example in which you have calculated the volume of a cuboid, the
VolumeOfCuboid did not return any value. But when the program executes, the volume of cube gets
calculated and assigned the variable “volume” to it, then it returns a value. However, it becomes
useless if the function doesn’t return.
To implement return function in the volume of a cuboid.
Step 1 The code for calculating the volume of cuboid is:
Step 2 Click on the ‘Functions’, select ‘return’ block. Drag and place it in the function block and
add the variable ‘volume’ to its text area as shown below
Advanced MakeCode Arcade 61

