Pseudocode Foundations & Conventions: Common Pseudocode Keywords And Their Correct Usage (Copy)
Common Pseudocode Keywords And Their Correct Usage
Purpose Of Pseudocode Keywords
- Keywords define structure, control, and flow of logic
- Correct keyword usage helps examiner:
- Identify logic instantly
- Allocate marks correctly
- Incorrect or mixed keyword usage causes:
- Loss of method marks
- Ambiguous logic interpretation
Core Structural Keywords
| Keyword | Purpose | Correct Usage |
|---|---|---|
| DECLARE | Create variable | DECLARE Total : INTEGER |
| CONSTANT | Fixed value | CONSTANT PassMark ← 50 |
| INPUT | Read data | INPUT Age |
| OUTPUT | Display data | OUTPUT “Total = “, Total |
Example (Basic Structure)
DECLARE Age : INTEGER
INPUT Age
OUTPUT "Age = ", Age
Assignment And Comparison Keywords
| Operation | Keyword / Symbol | Correct Example |
|---|---|---|
| Assignment | ← | Total ← Total + Value |
| Equal to | = | IF Age = 18 THEN |
| Not equal | <> | IF Score <> 0 THEN |
| Greater than | > | IF Marks > 50 THEN |
| Less than | < | IF Time < Limit THEN |
- ← is only for assigning values
- = is only for comparison inside conditions
Logical Keywords
| Keyword | Purpose | Example |
|---|---|---|
| AND | Both conditions true | IF A > 0 AND B > 0 THEN |
| OR | Either condition true | IF Choice = 1 OR Choice = 2 |
| NOT | Reverse condition | IF NOT Found THEN |
Examiner-Friendly Condition
IF (Age >= 18) AND (HasID = TRUE) THEN
OUTPUT "Allowed"
ENDIF
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
Selection Control Keywords
| Keyword | Purpose |
|---|---|
| IF | Start decision |
| THEN | Start IF block |
| ELSE | Alternative block |
| ENDIF | End IF structure |
| CASE | Multi-option selection |
| OTHERWISE | Default case |
| ENDCASE | End CASE |
IF–ELSE Example
IF Score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
CASE Example
INPUT Option
CASE Option OF
1 : OUTPUT "Add"
2 : OUTPUT "Delete"
OTHERWISE : OUTPUT "Invalid"
ENDCASE
Loop Control Keywords
| Loop Type | Start Keyword | End Keyword |
|---|---|---|
| Count-controlled | FOR | ENDFOR |
| Pre-condition | WHILE | ENDWHILE |
| Post-condition | REPEAT | UNTIL |
FOR Loop
FOR i ← 1 TO 10
OUTPUT i
ENDFOR
WHILE Loop
WHILE Count < 5 DO
INPUT Value
Count ← Count + 1
ENDWHILE
REPEAT UNTIL Loop
REPEAT
INPUT Age
UNTIL Age >= 0 AND Age <= 120
Loop Support Keywords
| Keyword | Purpose |
|---|---|
| TO | Upper bound in FOR |
| DO | Start WHILE block |
| UNTIL | Stop REPEAT loop |
- UNTIL condition ends the loop when TRUE
- DO must appear in WHILE loops
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
Procedure And Function Keywords
| Keyword | Purpose |
|---|---|
| PROCEDURE | Task-based module |
| FUNCTION | Value-returning module |
| RETURNS | Function return type |
| RETURN | Send value back |
| CALL | Execute procedure |
PROCEDURE Example
PROCEDURE DisplayResult(Mark : INTEGER)
OUTPUT Mark
ENDPROCEDURE
CALL DisplayResult(Score)
FUNCTION Example
FUNCTION GetAverage(Total : INTEGER, Count : INTEGER) RETURNS REAL
RETURN Total / Count
ENDFUNCTION
Average ← GetAverage(Sum, N)
Parameter Direction Keywords (When Used)
| Keyword | Meaning |
|---|---|
| BYREF | Changes affect caller |
| BYVAL | Copy passed only |
PROCEDURE UpdateTotal(BYREF Total : INTEGER, Value : INTEGER)
Total ← Total + Value
ENDPROCEDURE
Array And Record Keywords
| Keyword | Purpose |
|---|---|
| ARRAY | Store multiple values |
| OF | Define data type |
| RECORD | Define structured type |
| ENDRECORD | End record definition |
ARRAY Example
DECLARE Marks : ARRAY[1:10] OF INTEGER
RECORD Example
RECORD StudentType
Name : STRING
Age : INTEGER
ENDRECORD
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
File Handling Keywords (AS Level Scope)
| Keyword | Purpose |
|---|---|
| OPENFILE | Open file |
| READFILE | Read line |
| WRITEFILE | Write line |
| CLOSEFILE | Close file |
| EOF | End of file check |
File Reading Pattern
OPENFILE DataFile FOR READ
WHILE NOT EOF(DataFile) DO
READFILE DataFile, Line
OUTPUT Line
ENDWHILE
CLOSEFILE DataFile
Boolean Literal Keywords
| Keyword | Meaning |
|---|---|
| TRUE | Boolean true |
| FALSE | Boolean false |
Found ← FALSE
Common Keyword Misuse And Fixes
| Mistake | Correct Form |
|---|---|
| Using = for assignment | Use ← |
| Using PRINT | Use OUTPUT |
| Using READ | Use INPUT |
| Missing ENDIF | Always close blocks |
| Using UNTIL like WHILE | UNTIL stops loop |
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
Examiner-Approved Keyword Checklist
| Check | Status |
|---|---|
| Correct assignment operator | ✓ |
| Correct loop keywords | ✓ |
| Proper block endings | ✓ |
| No language-specific terms | ✓ |
| Clear keyword consistency | ✓ |
