Introduction to Procedural Programming with Elan

# Getting started

To undertake procedural programming (PP) in Elan, ensure that Elan is set to the Procedural profile from the menu at the top of the IDE. This will ensure that:

- The list of demo programs will now show only programs that use PP.
- The options shown on the new code menus in the editor are all appropriate to PP
  - At the global level, it will offer: concrete class, abstract class, and interface Each of these allows you to create a ‘user-defined type’ – that may then be used in a similar fashion to the standard types such `IntintintIntegerint`, `StringstrstringStringString`, or `ListlistListListList`. (Enums - which are single-line instructions - are not directly associated with OOP, but because an enum is a very simple form of user-defined type, it is made available in the same profile.)
  - Within a concrete class, abstract class, or interface, the new code menu will show an entirely new list of instructions, collectively known as ‘members’ (plus comment) that may be defined within those three new global instructions.

This is an explanation of core concepts, not a tutorial. Specifics of e.g. library techniques should reference LibRef

# Principle 1: A procedural program consists of sequences of commands

initially in main, later in functions and procedures each instruction is a command that leaves the system in a different state contains instructions executed, by default, in order they are defined (later can exercise more control over the flow of control) each instruction is a command that changes the state of the system instructions are of different kinds comments are not instructions but may be added wherever an instruction may be

# Principle 2: Values may be literal or named, and of different types

value types literal values named values variables constants enums

# Principle 3: Expressions derive more useful information from existing values

Can be thought of as queries This section covers operators, and library function calls

# Principle 4: Writing automated tests is useful and satisfying

# Principle 5: Writing your own functions extends the language

# Principle 6: Selection permits alternative paths through the instructions

# Principle 7: Iteration allows the same instructions to be executed multiple times

... on different data Iteration also called looping

## When you know how many iterations in advance, use a 'for' loop

## When you don't know how many iterations in advance, use a 'while' loop

# Principle 8: Data structures hold multiple, related, data items in one name List is the most common List facilitates iteration over related items of the same kind String may be considered a data structure, but it is limited Tuple

# Principle 9: Input/Output is done in the main routine, or procedures

What is a procedure Ready made and user-defined The difference

# Principle 10: Exceptions handle unexpected behaviour

nature try catch throw Use exceptions only to handle errors that can't be handled another way