EZ Programing Demos

Slow motion, step by step, animated demonstrations of basic computer programing techniques

Links to topics:

Current topic:

About functions....

Functions return values dependent upon what input they are given. Below are several links to articles about specific functions demonstrated at this site, and below those links is some further introductory explanation about functions.


Think this way....

You have a function:

    The function


You give it a value, usually a number, called the input:

    The input: 5


The function gives you back a value, usually a number, called the output. The function matchs an output with the input:

    The output: 10


A different input value usually, but not necessarily, matches up with a different output value:

    Another input, 3, and another output, 6


The rules for how the input value and output value match with each other are collectively called the definition or behavior of the function. In the example above the function doubles the input to produce the output.


There is much more to the meaning of the term function than we are presenting here. The above explanation covers much of the way the term is used in mathematics. In computer languages the term function works this way when you are doing mathematics in the language, and that is what we will be doing in this section of EZ Programing Demos.

Computer languages usually have the ability to do mathematics with functions. A function used this way would have a name, an input, and an output.

Lets say we have an imaginary computer language that has a function that works this way: You give it a number, and it gives you back the absolute value of that number. So, if you gave it -3 (as input), it would return 3 (as output). Let's give this function a name; let's call it abs. A computer line like the following would print the absolute value of -3:

    print abs(-3);

Points to understand:

  • A set of parentheses follows the function name.
  • What is placed within the parentheses represents the input to the function (-3 here).
  • Think of the output of the function (3 here) as appearing at the function's location. That is, in your imagination replace abs(-3) with 3.
  • The print command prints the output of the function, 3.

This code would print 5:

    print 2 + abs(-3);

The above links to articles present several demos illustrating many common mathematical functions found in computer languages.


Suggested next article:

EZ Math Movie is a site that can help you experiment with and understand many topics in mathematics. Its main feature is an interactive animated (x, y) graph that you control with an actual programing language. There are many examples and tutorials, and EZ Math Movie is crossed referenced with both EZ Programing Demos and Zona Land Education.


Zona Land Education is a site with explanations and interactive diagrams covering many topics in physics and mathematics. Zona Land Education is cross referenced with EZ Math Movie, and it contains several animations that use EZ Math Movie's programing language.