Control Structures

All computer programs are written in one or more of three basic control (logic) structures. These control structures are: (a) sequence, (b) selection, and (c) repetition. Control structures control a program’s flow of logic.

Sequence Structure

The sequence structure is used in every computer program. This structure instructs the computer to process instructions one-by-one. An example of this type of structure might be: (a) reading a recipe, (b) driving directions, or (c) solving math problems. The processing starts at step one, and follows through, step-by-step, until step N. The steps used to solve problems are called algorithms. The sequence structure can be used inside of the selection structure, or, inside of a repetition structure.

Selection Structure

The selection (decision) structure directs a computer to make a decision based on a specified condition. An example of a selection structure might be: (a) if an order total is less than a customer’s credit limit, authorize the transaction, otherwise, decline the transaction. A selection structure can be used inside of a repetition structure.

Repetition Structure

The repetition structure, sometimes referred to as an iteration or loop, directs a computer to repeat one or more instructions until a specified condition has been met. An example of a repetition structure might be: (a) read a file line-by-line, until the entire file has been read. The repetition structure can be used inside of a decision structure.

One Comment

Leave a Reply