Writing a function
Let's see what a function looks like in code:
function name() code within this function more function code end_function
Here, we see that a function has a name, just like a variable. The conventions used by a language for naming functions are usually the same as those used for variables. If you don't remember what those were, you can find them in Chapter 6, Working with Data – Variables, in the Naming conventions section.
After the function name, we find open and close parentheses. Whenever we refer to this function, they will be included after the name. They will also have another use, which we will see later in this chapter.
After that, we see a code block, the body of loops and if
statements, for example. This is the code that will be executed when the function is called.
A function can be called just by using its name, and we must not forget the parentheses. Calling the preceding function would...