Functions

A function is a sequence of instructions with a defined start and end, and lists of variables that it gets, uses and returns.

Computer programs are sequences of instructions that tell the computer what to do. A sequence of instructions must have a defined start and end. The instructions operate on variables. The function defines the variables that the function takes, uses and returns.

Parts

  • Name
  • Parameters – input variables
  • Return variable type
  • Local variables
  • Lines – instructions
  • Comments

Name

The name of the function.

For more information, see identifiers.

Parameter

A parameter is a variable that the calling function sets.

The function can modify the parameters.

For more information, see Variables.

Return variable type

The return variable is a variable that is set by the function and read by the calling function.

The function specifies the type of the return variable.

For more information, see Variables.

Local Variable

A variable used by the function itself.

For more information, see Variables.

Line

One or more instructions that tell the computer what to do.

For more information, see Line.

Return line

A line that specifies or creates the data that is returned from the function.

For more information, see Line.

Comment

Comments are text that explains or describes the instructions of a function to a person reading the program.

For more information, see Comments.