3.1.13 Structuring the Logic

3.1.13 Structuring the Logic

Solution steps of all problems can be organised into one or a combination of the following three forms known as control structures.

  • Sequence structure
  • Branching structure
  • Looping structure

A sequence structure is used when the solution does not involve any repetitive operations or options. This is known as straight-line logic (see the figure below).

Branching refers to the process of following one of two or more alternate paths of computations. This happens at a point where a 'test' is performed to identify the conditions of certain variables in the process. The basis for selection of a particular path is state d within the decision box. The decision can be based on a comparison, on the value of a variable, on the sign of a variable, etc.

Looping refers to the repeated use of one or more steps. There are two types of loops. One is known as fixed loop where the o perations are repeated a fixed number of times. In. this case, the values of the variables inside the loop have no effect on the number of times that the looping operation is performed. The other is known as variable loop where the operations are repeated until a specified condition is met. Here, the number of times that the loop is repeated may vary. Searching for a particular item in a list is an example of variable loop.

Loops are also referred to as backward Jumps. These jumps may occur either after me eting a specified condition in the process or after doing a certain computation.

Last modified: Friday, 22 June 2012, 7:05 AM