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:

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