In the last two posts we looked at control structures as part of the programming series here on Tech Tuesdays. We saw that loops let us repeat a sequence of instructions, which is one way of having to avoid writing the same code over and over again. Today we will learn about another and more powerful technique: the definition of new words that can then be used anywhere in the program. You may recall the example of nautical terms from the post on programming languages:
For instance, if I tell another sailor to “jump the main halyard” they will know exactly what to do because this is an expression with a precise meaning. I could of course also have given a lengthy description using general purpose instead of nautical English by saying something like “find the rope that runs from the top of the big sail to the top of the mast and then back down and then pull on it by jumping up and letting your weight help you.”
Learning the nautical terms once means that now every time you hear the term you have access to the sequence of steps for which it stands. In programming we do this by defining a new word that becomes part of the vocabulary available in that program (and potentially in other programs) going forward.
Let’s start with a simple example that we already encountered in the post on syntax. Not every programming language has a built in way of calculating the so-called factorial of n, which is the product of every number from 1 up to and including n. Here is a short piece of code that accomplishes this
![highlight](https://storage.googleapis.com/papyrus_images/81b2dbc054f225b21669afbe15604c65.webp)
![Continuations logo](/_next/image?url=https%3A%2F%2Fstorage.googleapis.com%2Fpapyrus_images%2Fe3f4eb1044178c979fd42b642565dbab.jpg&w=384&q=75)