Difference between revisions of "Functions - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "In this sense, a function is a type of procedure or routine. Some programming languages make a distinction between a function, which returns a value, and a procedure, which pe...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
A function is a module of code that performs a given task on data passed to it as parameters, this block will then return a value back. Furthermore functions can be called throughout your program and even in other functions once they are written.
 +
 
In this sense, a function is a type of procedure or routine. Some programming languages make a distinction between a function, which returns a value, and a procedure, which performs some operation but does not return a value. Most programming languages come with a prewritten set of functions that are kept in a library.
 
In this sense, a function is a type of procedure or routine. Some programming languages make a distinction between a function, which returns a value, and a procedure, which performs some operation but does not return a value. Most programming languages come with a prewritten set of functions that are kept in a library.
 +
 +
==Example of a function==
 +
 +
<syntaxhighlight lang="csharp">
 +
    private double CalculateRandomValue(int BaseValue, int Variability)
 +
    {
 +
      return BaseValue - (BaseValue * Variability / 100) + (BaseValue * Rnd.Next(0, (Variability * 2) + 1) / 100);
 +
    }
 +
</syntaxhighlight>
 +
 +
As you can see the function above is from the Warren class, it specifies the data type (after private) and must have a return command to pass the value back.

Latest revision as of 06:28, 26 May 2017

A function is a module of code that performs a given task on data passed to it as parameters, this block will then return a value back. Furthermore functions can be called throughout your program and even in other functions once they are written.

In this sense, a function is a type of procedure or routine. Some programming languages make a distinction between a function, which returns a value, and a procedure, which performs some operation but does not return a value. Most programming languages come with a prewritten set of functions that are kept in a library.

Example of a function

    private double CalculateRandomValue(int BaseValue, int Variability)
    {
      return BaseValue - (BaseValue * Variability / 100) + (BaseValue * Rnd.Next(0, (Variability * 2) + 1) / 100);
    }

As you can see the function above is from the Warren class, it specifies the data type (after private) and must have a return command to pass the value back.