Pseudocode Foundations & Conventions: Variables, Constants And Identifiers In Pseudocode (Copy)
Variables, Constants And Identifiers In Pseudocode
Role Of Variables, Constants And Identifiers
- They define what data is stored, how it is accessed, and how logic is understood
- Examiner checks:
- Correct declaration
- Correct naming
- Correct usage throughout the algorithm
- Poor identifier usage causes:
- Ambiguity
- Tracing difficulty
- Loss of easy structure marks
Variables (Changeable Data Storage)
| Aspect | Correct Practice |
|---|---|
| Must be declared | Before use |
| Must be initialised | Before processing |
| Meaningful name | Describes purpose |
| Correct data type | Matches stored value |
Variable Declaration Format
DECLARE Age : INTEGER
DECLARE Name : STRING
DECLARE Average : REAL
DECLARE Found : BOOLEAN
Variable Initialisation Examples
Age ← 0
Name ← ""
Average ← 0
Found ← FALSE
- Variables can change during execution
- Initialisation prevents undefined behaviour
Common Variable Types (AS Level Scope)
| Data Type | Used For | Example |
|---|---|---|
| INTEGER | Whole numbers | Count, Age |
| REAL | Decimal numbers | Average, Price |
| STRING | Text | Name, Address |
| BOOLEAN | True / False | Found, Valid |
| CHAR | Single character | Grade |
Variable Naming Rules (Examiner-Friendly)
| Poor Name | Problem | Correct Name |
|---|---|---|
| x | No meaning | TotalMarks |
| a1 | Unclear | StudentAge |
| t | Ambiguous | Total |
| flag | Vague | Found |
- Names must describe purpose, not data type
- Examiner should understand meaning instantly
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Constants (Fixed Values)
| Feature | Rule |
|---|---|
| Value never changes | Must remain constant |
| Declared once | At start |
| Named clearly | Uppercase recommended |
Constant Declaration
CONSTANT PassMark ← 50
CONSTANT MaxStudents ← 30
Using Constants In Logic
IF Score >= PassMark THEN
OUTPUT "Pass"
ENDIF
- Improves readability
- Avoids “magic numbers”
Constants Vs Variables
| Feature | Variable | Constant |
|---|---|---|
| Value changes | Yes | No |
| Assignment allowed | Yes | No |
| Purpose | Temporary storage | Fixed reference |
- Never reassign a constant
- Using constants improves exam clarity
Identifier Rules (What Counts As An Identifier)
- Identifiers include:
- Variable names
- Constant names
- Procedure names
- Function names
- Array names
- Record field names
Identifier Naming Conventions
| Identifier Type | Naming Style | Example |
|---|---|---|
| Variable | Descriptive noun | TotalMarks |
| Constant | Uppercase | PASSMARK |
| Procedure | Verb-based | DisplayResult |
| Function | Verb / Get… | GetAverage |
| Boolean | Yes/No meaning | Found, Valid |
- Avoid single-letter identifiers
- Avoid names that look like keywords
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Identifier Consistency (Critical For Tracing)
| Bad Practice | Problem |
|---|---|
| Using Total and total | Case confusion |
| Using Marks and Mark | Logical ambiguity |
| Renaming mid-program | Tracing error |
Correct Consistent Usage
DECLARE TotalMarks : INTEGER
TotalMarks ← 0
TotalMarks ← TotalMarks + Score
- Same spelling
- Same capitalisation
- Same meaning throughout
Declaring Multiple Variables Clearly
Poor Practice
DECLARE A, B, C : INTEGER
Examiner-Friendly
DECLARE Count : INTEGER
DECLARE Total : INTEGER
DECLARE Score : INTEGER
- Easier to trace
- Easier to award marks
Variables In Expressions
Average ← Total / Count
- Left side: single variable
- Right side: expression
- Expression may include:
- Variables
- Constants
- Operators
Boolean Variables (Flags)
| Purpose | Example |
|---|---|
| Control loop exit | Found |
| Track conditions | Valid |
Found ← FALSE
IF Value = Target THEN
Found ← TRUE
ENDIF
- Flags must always be initialised
- Flags improve loop control clarity
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Variables In Loops
Counter Variable
Count ← 0
WHILE Count < 5 DO
INPUT Value
Count ← Count + 1
ENDWHILE
Accumulator Variable
Total ← 0
FOR i ← 1 TO 10
Total ← Total + Marks[i]
ENDFOR
- Counter controls repetition
- Accumulator stores running total
Variables With Arrays
DECLARE Marks : ARRAY[1:10] OF INTEGER
- Array name is an identifier
- Index must be an INTEGER variable
FOR i ← 1 TO 10
OUTPUT Marks[i]
ENDFOR
Variables With Records
RECORD StudentType
Name : STRING
Age : INTEGER
Score : INTEGER
ENDRECORD
DECLARE Student : StudentType
Student.Score ← 85
- Record fields are identifiers
- Field access must be explicit
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions And 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Reserved Words (Identifiers Must Avoid These)
- IF, THEN, ELSE, ENDIF
- FOR, TO, ENDFOR
- WHILE, DO, ENDWHILE
- PROCEDURE, FUNCTION, RETURN
- INPUT, OUTPUT
| Incorrect Identifier | Why Wrong |
|---|---|
| DECLARE IF : INTEGER | Keyword |
| DECLARE FOR : INTEGER | Keyword |
Examiner Traps And Safe Practices
| Trap | Fix |
|---|---|
| Uninitialised variable | Initialise immediately |
| Confusing variable names | Use descriptive names |
| Reassigning constants | Never assign again |
| Mixed identifier styles | Stay consistent |
| Over-short names | Expand for clarity |
Examiner-Safe Declaration Template
DECLARE Count : INTEGER
DECLARE Total : INTEGER
DECLARE Average : REAL
DECLARE Found : BOOLEAN
Count ← 0
Total ← 0
Average ← 0
Found ← FALSE
- Clean
- Traceable
- Examiner-approved
