Programming Concepts (Copy)
IGCSE / O Level Computer Science Cheat Sheet
Topic: 8.1 Programming Concepts
🗃️ Variables and Constants
| Term | Description |
|---|---|
| Variable | A named memory location whose value can change during execution |
| Constant | A named value that does not change during program execution |
🧮 Basic Data Types
| Data Type | Description | Example |
|---|---|---|
| Integer | Whole numbers | 5, -12 |
| Real | Decimal numbers | 3.14, -0.01 |
| Boolean | True or False | TRUE, FALSE |
| Char | Single character | ‘A’, ‘3’ |
| String | Sequence of characters | “Hello123” |
⌨️ Input / Output
- INPUT: Get value from user
INPUT name
- OUTPUT: Display value
OUTPUT "Your name is", name
🔁 Programming Constructs
| Construct | Description | Syntax Example |
|---|---|---|
| Sequence | Statements executed in order | a ← 2, b ← 3, c ← a+b |
| Selection | Chooses between conditions | IF a > b THEN OUTPUT a |
| Iteration | Repeats a block of code | FOR i ← 1 TO 10 |
Types of Loops:
- Count-controlled:
FOR i ← 1 TO 5 - Pre-condition:
WHILE condition DO - Post-condition:
REPEAT ... UNTIL condition
➕ Totalling & Counting
- Totalling:
total ← total + value - Counting:
count ← count + 1
🔤 String Handling
| Operation | Description | Example |
|---|---|---|
LENGTH(s) |
Returns number of characters | LENGTH("CAT") → 3 |
SUBSTRING(s, x, y) |
Extracts part of string | SUBSTRING("HELLO", 2, 3) → "ELL" |
UPPER(s) |
Converts to uppercase | UPPER("hi") → "HI" |
LOWER(s) |
Converts to lowercase | LOWER("HELLO") → "hello" |
🔢 Operators
Arithmetic Operators:
+,-,*,/,^,MOD,DIV
Relational/Logical Operators:
=,<,<=,>,>=,<>(≠)
Boolean Operators:
AND,OR,NOT
🔁 Nested Statements
- One selection or loop inside another
FOR i ← 1 TO 5 IF i MOD 2 = 0 THEN OUTPUT i
🔧 Procedures & Functions
| Feature | Procedure | Function |
|---|---|---|
| Returns | No return value | Returns a value |
| Parameters | Optional | Optional |
| Use | Perform task | Perform task and return result |
- CALL procedureName(x, y)
- RETURN value in functions
🌐 Local vs Global Variables
| Scope | Description |
|---|---|
| Local | Accessible only within procedure/function |
| Global | Accessible throughout the whole program |
🛠️ Maintainability
Best practices for clean and maintainable code:
- Meaningful identifiers (
totalScore, notx) - Comments to explain purpose of code
- Use of procedures/functions to modularize code
- Proper indentation and formatting
