Algorithm Design - Control Structures
Algorithm Design - Control Structures
control structures
By Lachlan Wilson
What is the control structure?
In simple terms the control structure is the
type of algorithm. The structure could be
repetition, sequence or selection. Each
of these is needed for a different purpose
within a program. E.g. a repetition may
be used to restart the sequence of code
in the algorithm until and event occurs.
Selection
This control structure allows the program
to choose between one of two or more
alternative paths of intructions. The
choosing process involves evaluating
something called the ‘selector’ (used to
choose which path for the program to go)
and depending on the value of the
selector decides which sets of
instructions the program will execute.
Repetition
This is basically where a program will
repeat a set of instructions until it
reaches a certain point where an event
has occurred. An event may be a certain
number of repetitions must be completed
or a certain value must be entered. An
example of repetition is in a quiz where
you will get asked the same question
until you answer the question correctly.
Sequence
A sequence is a basic program and the
default program. A sequence is basically
where the code just follows one linear
path until it reaches the end. A basic
example of this would be putting in your
details and at the end receiving a
message containing these details.
More Examples of each
Sequence: A converter e.g. Binary to
decimal.
Repetition: A quiz where you must get
every answer right or you must start over
again.
Selection: A game where you are asks you
questions to find out what object you are
thinking about.