Skip to main content

Cambridge IGCSE & O Level Computer Science Programming Book for Microsoft Visual Basic Sample

Page 34

We are working with Cambridge Assessment International Education towards endorsement of this title. Any references or material related to answers, grades, papers or examinations are based on the opinion of the author(s). CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: PROGRAMMING BOOK

Introduction Many sporting activities make use of a limited range of approaches. Racket sports – such as badminton, for example – consist of a surprisingly limited number of different shots. Drop shots close to the net, long cleared shots to the back of the court and harddriven shots account for a large proportion of the shots used in a game. The skill is in combining those shots effectively to win the game.

construct: a method of controlling the order in which the statements in an algorithm are executed.

LE

Programming also makes use of a limited range of constructs to achieve satisfactory solutions to complex tasks. Like a good badminton player, who combines different shots to win a game, an effective programmer will combine different constructs to produce efficient programs.

KEY WORD

2.1 Programming concepts

Visual Basic and other procedural languages make use of three basic programming constructs (Table 2.1). Combining these constructs provides the ability to create code that will follow a logical process. The order in which the code is executed.

Selection

Providing options that will allow the execution (running) to follow a different path through the program based on certain criteria.

Iteration

Repeating a sequence of steps during the execution of the code.

Table 2.1: Programming concepts

P

Sequence

M

In Computer Science, the term ‘execute’ means the operation of a computer program. When a computer program is operating, it is being executed. The term ‘run’ is also used to describe the same process. The ‘program is running’ or the ‘program is being executed’ both mean the same thing.

Sequence

A

The order in which a process is completed is often crucial to the success of that process. Take the mathematical expression A + B × C + D. The rules of precedence dictate that the multiply operation (B × C) will be completed first. Had the programmer wanted A + B and C + D to be completed before multiplying the two resultant values then they would have had to be explicit about the required sequence: (A + B) × (C + D).

S

To calculate the time it takes to complete a journey, you need to know the distance to be travelled and the speed you will travel. The first logical step would therefore be to calculate the distance to be travelled as, without this data, you could not complete the rest of the task. Most tasks will involve different steps, and those steps often have to be completed in some logical sequence. When designing computer programs to achieve tasks, it is crucial to consider the sequence in which the task needs to be completed.

KEY WORDS

sequence: code is executed in the order it is written. selection: code follows a different sequence based on what condition is chosen. iteration: code repeats a certain sequence a number of times depending on certain conditions.

TIP The mathematical rule of operation precedence, commonly known as BODMAS, also applies to operators used in programming in the same way it applies to normal mathematical calculations.

22 Original material © Cambridge University Press 2021. This material is not final and is subject to further changes prior to publication.


Turn static files into dynamic content formats.

Create a flipbook
Cambridge IGCSE & O Level Computer Science Programming Book for Microsoft Visual Basic Sample by Cambridge International Education - Issuu