Introduction to Pseudocode for IGCSE Paper 2
Purpose of Pseudocode
- Represents code in a language-like format.
- Simplifies complex coding tasks.
- Examines logic over syntax.
- Fundamental for understanding various programming languages.
- Flexible and adaptable to future languages.
Importance in IGCSE
- Focuses on the logic and efficiency of the pseudocode.
- Encourages the understanding of the code structure.
Components of Pseudocode
Basics Covered in Chapter One
- Font Style and Size: Mono-spaced (fixed width).
- Indentation: Indicates the start and end of code segments.
- Indent by four spaces for code contained within a statement.
- Two-space indentation for line continuation.
- Case and Italics: Very precise.
- Keywords: Always in uppercase.
- Identifiers: Mixed case (e.g., NumberOfPlayers).
- Meta variables: Hold simplified versions of statements.
- Lines and Numbering: Code lines are consecutive and executed in order.
- Comments: Use double slashes
//
to add non-executable explanations within the code.
Data Types and Variables
Atomic Type Names
- Integer: Whole numbers.
- Real: Numbers with fractional parts (decimals).
- Char: Single characters (e.g.,
a
, B
).
- String: Series of characters (e.g.,
Hello
).
- Boolean: True or false values.
Identifiers and Assignments
- Identifiers: Can be variables, constants, procedures, and functions.
- Must start with a letter.
- Use camel case (e.g.,
numberOfPlayers
).
- Assignments: Use an arrow (
<-
) to assign values to variables.
Operations in Pseudocode
Input and Output
- Keywords:
INPUT
to take user input.
OUTPUT
to display output.
- Can use
READ
and PRINT
as alternatives to INPUT
and OUTPUT
.
Arithmetic Operations
- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Division:
/
Logic Operators
- AND, OR, NOT: Used in complex expressions.
Control Structures
If Statements (Selection Loop)
- Basic structure:
IF (condition) THEN (statement) ENDIF
- Nested if statements: Multiple if statements within each other.
Case Statements
- Used to handle multiple values of a variable.
For Loop (Count-Controlled Loop)
- Structure:
FOR (variable) <- (value) TO (value) DO (statement) ENDFOR
- Executes a set number of times.
Repeat Until Loop (Post-Condition Loop)
- Structure:
REPEAT (statement) UNTIL (condition)
- Continues until the condition becomes true.
While Loop (Pre-Condition Loop)
- Structure:
WHILE (condition) DO (statement) ENDWHILE
- Executes as long as the condition is true.
Arrays
Structure and Usage
- 1D Arrays: Simple lists of elements indexed by position.
- Example:
studentNames: ARRAY[1..30] OF STRING
- Assigning Arrays: Assign values to specific index positions in arrays.
Examples
studentNames[1]
would access the first element in the array.
- Arrays are used to manage lists of items.
Summary
- Understanding pseudocode fundamentals helps in learning programming.
- Practice with questions and real-life examples enhances comprehension.
Keywords and Symbols
- Remember important keywords and symbols.
- Example Keywords:
INPUT
, OUTPUT
, IF
, FOR
, WHILE
.
- Symbols include arithmetic and logical operators.
Note: Detailed guides and practice questions will aid in mastering pseudocode.
End of Notes