There are a number of programming terms that need to be explained such as variable assignment, function, first-class function, conditional execution, and iterative execution (loop).

Variables

A variable is a placeholder for a data value. At any time, this data value can be replaced by another data value. The act of replacement is called assignment, that is to say, you can assign a new value to the variable. In other words, the data value that a variable can hold is variable. That’s why it’s called a variable!

A common way to denote assignment in a programming language is with the ‘:=’ symbol, for example,

What this says is, take the current value of x and subtract 1 from it. Then replace the value of x with this new result.

Functions

In a program, you execute instructions or statements one at a time in sequence. In a very long program, this can quickly become very unwieldy. So we introduce the idea of a function, which is a group of statements that can be called whenever and wherever we like in the program. A function lets us break out of the current sequence of execution we’re doing and jump to another location where we execute the function’s statement group.

Of course, after the function’s statement group is fully executed, we must return to where we left off in the original sequence of execution.

A function can accept arguments or data values that it uses to do its job.

A function can also return a particular data value to the original sequence of execution.

Here’s an example:

This function is called ‘fred’. It can accept 3 arguments: argument1, argument2, and argument3. It can return an integer value.

The statement ‘return 42’ returns the value 42 to whomever called function fred, for example:

Now, the variable ‘a’ holds the value 42 that was returned from function fred.

First-class Function

A first-class function is a function that can be assigned to a variable; not the value of the function return, but the actual function itself! In this way, the variable holding the function can be called just as if it was a function. For example,

‘a’ still holds the value 42 returned from function fred.

A first-class function can also accept functions as arguments!

A first-class function can also return a function as a return value!

First-class functions are really mind-blowing!

Conditional Execution

Groups of statements can be executed conditionally, that is to say, under certain conditions. For example,

Iterative Execution

Groups of statements can be executed repeatedly, as long as certain conditions hold true. For example,

This is often called a “loop.”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store