Cambridge IGCSE and O Level Programming Book
2.05 Pseudocode Pseudocode is a method of describing the logic and sequence of a system. It uses keywords and constructs similar to those used in programming languages but without the strict use of syntax required by formal languages. It allows the logic of the system to be defined in a language-independent format. This can then be coded using any programming language. Hence, the flow diagrams and pseudocode in this book are almost entirely the same as those used in the Visual Basic sister book of the series. Pseudocode follows a number of underlying principles: • Use capital letters for keywords close to those used in programming languages. • Use lower case letters for natural language descriptions. • Use indentation to show the start and end of blocks of code statements, primarily when using selection and iteration. One of the advantages of learning to program using Python is that the actual coding language is structured in a similar way to natural language and therefore closely resembles pseudocode. Python IDEs such as IDLE or Wing IDE also automatically indent instructions where appropriate. syllabus check
Pseudocode: understand and use pseudocode for assignment, using ←. 12
2.06 Pseudocode Example The following pseudocode is for an algorithm that accepts the input of two numbers. These values are added together and the result is stored in a memory area called answer. The value in answer is then displayed to the user. (In Chapter 3, we will learn that this memory area is known as a variable.)
INPUT number1 INPUT number2 answer ← number1 + number2 OUTPUT answer
Task
Note the use of ← to show the passing of values. This is pseudocode’s assignment operator. In pseudocode the equals symbol (=) is used to compare values. It is important to note that in Python the equals symbol is used for assignment and two equals symbols (==) are used to compare values.
Task 1 Construct a flowchart to represent this pseudocode example.