[go: up one dir, main page]

0% found this document useful (0 votes)
12 views5 pages

IGCSE 0478 Pseudocode Crash Course

The document is a crash course on IGCSE 0478 Pseudocode, covering essential syntax, core structures, and the differences between procedures and functions. It includes examples of assignment, loops, conditionals, arrays, and how to define and call procedures and functions. Additionally, it provides a practice problem for applying the concepts learned.

Uploaded by

Baasim Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

IGCSE 0478 Pseudocode Crash Course

The document is a crash course on IGCSE 0478 Pseudocode, covering essential syntax, core structures, and the differences between procedures and functions. It includes examples of assignment, loops, conditionals, arrays, and how to define and call procedures and functions. Additionally, it provides a practice problem for applying the concepts learned.

Uploaded by

Baasim Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

IGCSE 0478 Pseudocode Crash Course

Phase 1: Turbo Basics (under 20 minutes)

Syntax Essentials

• Assignment ( ← ): Use the left arrow for assignment, e.g. X ← 5 sets X to 5 1 .


• Pitfall: Don’t confuse assignment ( ← ) with comparison ( = ); use ← to store a value.
• Arithmetic: Use + , - , * , / as usual. For integer math, use DIV (integer division) and
MOD (remainder) 2 .
• Pitfall: Integer division ( DIV ) truncates the result. Always use parentheses to clarify order (e.g.
(A + B) * C ).
• Input/Output: Read values with INPUT var , and display with OUTPUT 3 . You can output
literals, variables or comma-separated items.
• Pitfall: Remember to output variables (not just compute them) if the exam question asks for
output.
• Comparison & Boolean logic: Use =, ≠, <, >, ≤, ≥ for comparisons. Combine conditions
with AND , OR , and NOT (all uppercase) 4 .
• Pitfall: Parenthesize complex conditions. For example,
IF (A ≥ 0 AND A < 10) OR NOT Flag THEN… .

INPUT age // read an integer into age


IF age ≥ 18 THEN // comparison and branching
OUTPUT "Adult"
ELSE
OUTPUT "Minor"
ENDIF

Core Structures

• IF…THEN…ELSE…ENDIF: Use an IF <condition> THEN … ENDIF block; include ELSE for


two-way decisions 5 . Always end with ENDIF . Indent the THEN / ELSE clauses by two
spaces (run-on lines should be avoided) 6 .
• Pitfall: Never forget the final ENDIF , and avoid writing ELSE IF on the same line—use nested
IFs instead.
• CASE…OF…OTHERWISE…ENDCASE: For multi-branch selection, use CASE <variable> OF
<value> : <statements> … OTHERWISE : <statements> ENDCASE 7 . Each case
(including OTHERWISE ) must end with a colon, and the block ends with ENDCASE .

• Pitfall: Don’t omit ENDCASE , and use OTHERWISE as the final case for “else”. Each case should
be a single statement or a simple block.

• FOR loop: Use a count-controlled loop:

1
FOR i ← start TO end [STEP increment]
<statements>
NEXT

This runs i from start up to end (inclusive) 8 . The default step is +1, or specify STEP k for
increments/decrements 9 .

• Pitfall: Always include NEXT (optionally followed by the loop variable for clarity). If start >
end , the loop body does not execute. Watch off-by-one errors (the loop includes both bounds).

• WHILE…DO…ENDWHILE: Use a pre-condition loop:

WHILE <condition> DO
<statements>
ENDWHILE

The condition is tested first; if true, the block executes and repeats until false 10 .

• Pitfall: Ensure the loop variable/condition changes inside the loop, or you’ll get an infinite loop
(or no execution if the condition is false initially).

• REPEAT…UNTIL: Use a post-condition loop:

REPEAT
<statements>
UNTIL <condition>

The body runs at least once, then repeats until <condition> is true 11 .

• Pitfall: Don’t forget UNTIL <condition> . If you need to loop until a password or valid input,
use REPEAT…UNTIL .

FOR i ← 1 TO 5 // FOR loop example


Sum ← Sum + i
NEXT
OUTPUT "Sum is ", Sum

WHILE count > 0 DO // WHILE loop example


OUTPUT count
count ← count - 1
ENDWHILE

REPEAT // REPEAT…UNTIL example


INPUT password

2
OUTPUT "Enter password"
UNTIL password = "secret"

• Arrays: Declare fixed-size arrays with bounds:

DECLARE A : ARRAY[1:10] OF INTEGER


DECLARE Matrix : ARRAY[1:3, 1:3] OF INTEGER

(Indices start at 1 by convention 12 13 .) Access elements with brackets: A[i] , or


Matrix[row, col] for 2D 14 15 .

• Pitfall: Always declare arrays with their size before use. You cannot assign to a whole slice at
once; use a loop to initialize many elements (e.g. FOR i ← 1 TO 10: A[i] ← 0 ). Remember
array bounds to avoid index errors.

• Strings: Use built-in string functions. For example, LENGTH(s) returns the length of string s
16 . To extract substrings, use something like SUBSTRING(s, start, count) (Cambridge
docs call this MID(s, start, count) 17 ). First character is position 1.

• Pitfall: Off-by-one is common (remember the first character is index 1). Calling SUBSTRING with
too large a range or negative indices should be avoided unless specified.

DECLARE Names : ARRAY[1:3] OF STRING


Names[1] ← "Ali"
Names[2] ← "Bala"
Names[3] ← "Cara"
Count ← LENGTH(Names[3]) // count = 4
Word ← "computer"
Part ← SUBSTRING(Word, 1, 4) // Part = "comp"

Procedures & Functions

• Procedures: A procedure does not return a value. Define with PROCEDURE and call with CALL
18 19 . Example:

PROCEDURE PrintHello()
OUTPUT "Hello!"
ENDPROCEDURE
CALL PrintHello()

• Pitfall: Don’t use RETURN in a procedure. Always end the block with ENDPROCEDURE . Use
CALL to invoke it.

• Functions: A function returns a single value. Define with FUNCTION name(parameters)


RETURNS <type> and use RETURN inside. Example:

3
FUNCTION Max(A : INTEGER, B : INTEGER) RETURNS INTEGER
IF A > B THEN
RETURN A
ELSE
RETURN B
ENDIF
ENDFUNCTION
Result ← Max(7, 10) // Result = 10

Functions are used as part of an expression (no CALL ) 20 21 .

• Pitfall: Never forget the RETURN statement (and its data type). Unlike procedures, do not write
CALL Max(...) ; instead use Result ← Max(...) .

Functions vs Procedures: The key difference is that functions return a value (and must be declared with
RETURNS <type> ), whereas procedures do not 20 . Use functions for calculations (so you can assign
their result) and procedures for actions (like printing or swapping).

• Parameters (BYVAL vs BYREF): By default, parameters are passed by value (the function/
procedure gets a copy) 22 . To pass by reference (allowing the routine to modify the caller’s
variable), prefix the parameter with BYREF in the definition 23 . Example:

PROCEDURE Swap(BYREF X : INTEGER, BYREF Y : INTEGER)


Temp ← X
X ← Y
Y ← Temp
ENDPROCEDURE

a ← 3, b ← 5
CALL Swap(a, b)
// Now a = 5 and b = 3

• Pitfall: If you want to change the caller’s variable, you must use BYREF . Omitting BYREF
means the original will not change. (Also, do not use BYREF with functions in Cambridge
pseudocode 22 .)

PROCEDURE DisplayRange(low : INTEGER, high : INTEGER)


OUTPUT "Range is ", low, " to ", high
ENDPROCEDURE

FUNCTION Square(x : INTEGER) RETURNS INTEGER


RETURN x * x
ENDFUNCTION

// Example calls
CALL DisplayRange(1, 10)
Value ← Square(5) // Value = 25

4
Practice Problem
Exercise: Write pseudocode to input an integer and check if it lies between 1 and 100 (inclusive). If it
does, output "In range" , otherwise output "Out of range" . Use an IF…THEN…ELSE structure
and OUTPUT.

Hint: You will need to INPUT the number, use a condition like IF num >= 1 AND num <= 100
THEN ... ELSE ... , and OUTPUT the appropriate message.

1 2 3 4 5 6 7 8 9 10 11 12 14 askpakchairul.files.wordpress.com
https://askpakchairul.files.wordpress.com/2015/05/0478_pseudocode_guide.pdf

13 15 16 17 18 19 20 Cambridge International AS & A Level 9618 Computer Science


21 22 23

Pseudocode Guide for Teachers for examination in 2026


https://www.cambridgeinternational.org/Images/697401-2026-pseudocode-guide-for-teachers.pdf

You might also like