What Does Function Mean?
A function is a unit of code that is often defined by its role within a greater code structure. Specifically, a function contains a unit of code that works on various inputs, many of which are variables, and produces concrete results involving changes to variable values or actual operations based on the inputs.
Techopedia Explains Function
Within a greater code structure, a function, which also may be called a subroutine or procedure, is “called” by the code, depending on a user event or as part of a greater operation. When called, the function operates on the inputs and produces the results.
A basic example is a function called “addone” that will take a variable x, which is defined as an integer, and add one. The code within addone would look something like this:
input “x”
x = x + 1
output “x”
An example of a function that operates on inputs instead may look like this:
input “x”
if x > 5 then
print x
end
Here, the function may or may not print, depending on the value of “x.”