Function arguments
Often, we want our functions to be somewhat flexible, so they don't do exactly the same thing every time we call them. Consider the following two functions:
function add_2_and_3() return 2 + 3 end_function function add_5_and 9() return 5 + 9 end_function
These two functions add two numbers and return the result. The first one adds 2
and 3
, and the second one does the same but with 5
and 9
. Now, these are just two pairs of numbers. If we would like to have a function that could add any numbers, we would need to create an endless number of functions.
But if we look at what the functions do, we can see that they are actually doing the same thing. They add two numbers and return the result. The only thing that changes are the numbers that are used in the addition operation.
What we want is to be able to pass the numbers we want to be added to the function so it can use them in the calculation, and by...