14 / 16

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(): Integer and select its block
  • add a new parameter x: Integer
  • click on the return block and type x * x
  • add a new Output block in the main function, and type square(5)

Run the program, it should display 25 in the output.