Function returning value
We saw how we can group some common code and wrap it in a function. We can parametrize it with different arguments when we call it.
Functions can also return a value.
Let's define a function: square(x).
It will calculate the square of a number.
Steps:
- add a new function
square(): Integerand select its block - add a new parameter
x: Integer - click on the
returnblock and typex * x - add a new
Outputblock in the main function, and typesquare(5)
Run the program, it should display 25 in the output.