Explain sequence, selection and iteration as used in computer programming; outline the benefits of having a variety of data types available to the programmer.

Authors Avatar

Code Structure

Task Brief

  • As Gary is fascinated about computer software, he would also like you (a) to explain sequence, selection and iteration as used in computer programming; (b) outline the benefits of having a variety of data types available to the programmer.

Contents

Introduction

In this report, I shall seek to explain how sequence, selection and iteration are used in computer programming. In order to do so, it first needs to be understood that they are all control structures, and as such are used to help dictate how a program should flow.

Sequence Flow

In a sequence control structure, statements are processed consecutively, from first to last, with no deviation. No decisions or comparisons have to be made with data, so the program simply runs the instructions and, once the last statement is completed, terminates. The following diagram illustrates this process as a flowchart:

(The VB Programmer LLC, 2006)

In order to illustrate how this flow appears in practicality, the following is a program I have written in Visual Basic to help illustrate this. The lines of code are number from 1 to 9 to show that each line is executed in order:

Join now!


In this example, the program does the following:

  • Three integer variables called Num(0), Num(1) and Num(2) are created (step 1).
  • The program asks and then prompts the user to enter a number (steps 2 to 4).
  • It then asks and then prompts the user to enter a second number (steps 5 to 6).
  • The sum of these two numbers is calculated (step 7).
  • The result is displayed on screen (step 8)
  • When the user inputs the enter key, the program terminates (step 9).

Selection / Decision Flow

Rather than being processed consecutively, selection allows the program to deviate ...

This is a preview of the whole essay