0% found this document useful (0 votes)
242 views3 pages

O Level Pseudocode Study Guide

The document provides comprehensive notes on O Level pseudocode for the 2026 syllabus, covering key concepts such as variables, data types, input/output, assignment, selection, iteration, procedures, functions, standard functions, file handling, and operators. It includes examples of each concept to illustrate their usage in programming. This serves as a guide for understanding the foundational elements of pseudocode in programming.

Uploaded by

jawadkaleem117
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)
242 views3 pages

O Level Pseudocode Study Guide

The document provides comprehensive notes on O Level pseudocode for the 2026 syllabus, covering key concepts such as variables, data types, input/output, assignment, selection, iteration, procedures, functions, standard functions, file handling, and operators. It includes examples of each concept to illustrate their usage in programming. This serves as a guide for understanding the foundational elements of pseudocode in programming.

Uploaded by

jawadkaleem117
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

■ O Level Pseudocode Notes (2026 Syllabus)

1. Variables and Constants


DECLARE variable → introduces a variable with a data type.
DECLARE age : INTEGER
DECLARE name : STRING

CONSTANT → a fixed value that cannot change.


DECLARE PI : REAL CONSTANT
PI ← 3.14159

2. Data Types
INTEGER – whole numbers
REAL – decimal numbers
STRING – text
CHAR – single character
BOOLEAN – TRUE / FALSE
ARRAY – collection of items of the same type
DECLARE marks : ARRAY[1:10] OF INTEGER

3. Input / Output
INPUT variable – get input from user
OUTPUT data – display data
INPUT name
OUTPUT "Hello " , name

4. Assignment
Use ← (or = in some papers)
total ← 0
total ← total + 5

5. Selection (Decision Making)


IF ... THEN ... ELSE
IF mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF

CASE Statement
CASE grade OF
'A' : OUTPUT "Excellent"
'B' : OUTPUT "Good"
'C' : OUTPUT "Fair"
OTHERWISE : OUTPUT "Invalid"
ENDCASE

6. Iteration (Loops)
FOR loop
FOR i ← 1 TO 5
OUTPUT i
NEXT i

WHILE loop
WHILE total < 100
INPUT num
total ← total + num
ENDWHILE

REPEAT ... UNTIL loop


REPEAT
INPUT guess
UNTIL guess = secret

7. Procedures and Functions


Procedure – performs a task, no return value.
PROCEDURE greet(name)
OUTPUT "Hello " , name
ENDPROCEDURE
CALL greet("Ali")

Function – returns a value.


FUNCTION square(x) RETURNS INTEGER
RETURN x * x
ENDFUNCTION
OUTPUT square(5)

8. Standard Functions
LENGTH(string) → number of characters
LEFT(string, n) → leftmost n chars
RIGHT(string, n) → rightmost n chars
MID(string, start, length) → substring
UPPERCASE(string) → all caps
LOWERCASE(string) → all small letters
ASC(char) → ASCII code of a character
CHR(code) → character from ASCII code
RANDOM() → random decimal between 0 and 1
ROUND(x) → nearest integer
INT(x) → integer part only (truncates)

9. File Handling
Open a file
OPENFILE "[Link]" FOR READ
OPENFILE "[Link]" FOR WRITE
OPENFILE "[Link]" FOR APPEND

Read from file


READFILE "[Link]", line

Write to file
WRITEFILE "[Link]", line

Loop until end of file


WHILE NOT EOF("[Link]")
READFILE "[Link]", line
OUTPUT line
ENDWHILE

Close file
CLOSEFILE "[Link]"

10. Operators
Arithmetic: + , - , * , / , DIV , MOD
Relational: = , <> , > , < , >= , <=
Logical: AND , OR , NOT

Common questions

Powered by AI

A procedure performs a specific task but does not return a value. For instance, 'PROCEDURE greet(name)' simply outputs a greeting without returning anything . Functions, on the other hand, perform a task and return a value, which can be used elsewhere in the code. An example is 'FUNCTION square(x) RETURNS INTEGER' that calculates and returns the square of x . Procedures are often used for tasks that require an action, like displaying a message, while functions are used when a result is needed, like calculating a mathematical operation to use in further computation .

Conditional statements in pseudocode, such as IF...THEN...ELSE and CASE, guide decision-making by executing specific blocks based on evaluated conditions. 'IF mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail"' enables branching based on student scores . The CASE statement, such as 'CASE grade OF 'A' : OUTPUT "Excellent" 'B' : OUTPUT "Good"', provides a cleaner structure for multi-conditional decisions, reducing complexity when handling numerous conditions . These statements enhance logic by offering structured pathways for divergent outcomes based on inputs, primarily improving readability and manageability of complex decision scenarios.

Logical operators like AND, OR, and NOT allow for combining multiple conditions within IF statements to control flow more precisely. For example, one could use 'IF age > 18 AND hasLicense THEN OUTPUT "Eligible to drive"' which combines two conditions that must both be true for the statement to execute . Using these operators, complex decision trees can be built, enabling more dynamic and responsive programs by allowing combinations of conditional checks, hence simplifying nested conditional logic .

A FOR loop is used when the number of iterations is known before the loop starts, with a specific range of values. For example, 'FOR i ← 1 TO 5' will iterate exactly five times . A WHILE loop doesn't have a known number of iterations beforehand and continues as long as a condition remains true. For example, 'WHILE total < 100' keeps looping while the total is less than 100 . REPEAT...UNTIL loops are similar to WHILE loops but always execute at least once, continuing until a condition becomes true. For example, 'REPEAT INPUT guess UNTIL guess = secret' ensures the loop runs until the correct guess is made .

Pseudocode data types include INTEGER, REAL, STRING, CHAR, BOOLEAN, and ARRAY, each serving distinct purposes . INTEGER is used for whole numbers, enabling arithmetic operations ideal for counting . REAL allows for decimal numbers, suitable for precise calculations . STRING manages text, supporting operations like concatenation . CHAR represents single characters, useful for individual character processing, while BOOLEAN holds TRUE/FALSE values, crucial for logic operations . ARRAYS store collections of a single data type, facilitating bulk data processing . These data types guide the operations and manipulations possible within variables, defining the relevant functional scope.

Standard functions such as LENGTH, LEFT, RIGHT, and MID facilitate string manipulation in pseudocode. LENGTH(string) returns the number of characters in a string, useful for validation steps . LEFT(string, n) retrieves the leftmost n characters, helpful for prefix extraction . RIGHT(string, n) extracts the rightmost n characters, useful in suffix analysis like identifying file extensions . MID(string, start, length) extracts a substring starting at 'start' for 'length' characters, aiding in partial data extraction like retrieving a middle name from a full name . These functions enable efficient and flexible string handling crucial in text processing applications.

An array in pseudocode is a collection of elements, where each element is of the same data type and accessible using an index. For example, 'DECLARE marks : ARRAY[1:10] OF INTEGER' defines an array of integers with 10 elements . Arrays are particularly useful when dealing with multiple related data items that require processing in a loop, such as storing and processing the test scores of 10 students where each score is accessed and potentially modified using a loop .

In pseudocode, arithmetic operators (+, -, *, /, DIV, MOD) are used for mathematical calculations like addition, subtraction, multiplication, division, integer division, and modulo operations respectively . Relational operators (=, <>, >, <, >=, <=) are used to compare two values, determining relationships such as equality, inequality, and ordinal comparisons . The key distinction is that arithmetic operators return numerical results, while relational operators return Boolean values (TRUE/FALSE), facilitating decision-making in control structures .

Constants in pseudocode, as declared with 'DECLARE PI : REAL CONSTANT PI ← 3.14159', represent fixed values that do not change throughout the program's execution . Their primary advantage is providing stability and clarity when identifiers should not be altered, minimizing errors by preventing unexpected changes. Constants are especially advantageous in contexts requiring fixed values for calculations, such as mathematical formulas (e.g., using PI in geometry), where the value should be consistent to ensure the correctness of computations .

File handling in pseudocode involves operations like opening, reading, writing, and closing files. 'OPENFILE "FileA.txt" FOR READ' prepares a file to read data, while 'OPENFILE "FileB.txt" FOR WRITE' prepares it to write data . Reading from a file can be executed through 'READFILE "FileA.txt", line', looping until EOF as 'WHILE NOT EOF("FileA.txt") READFILE "FileA.txt", line OUTPUT line ENDWHILE' . Writing is done via 'WRITEFILE "FileB.txt", line', transcribing processed data to an output file. Closing is essential, achieved through 'CLOSEFILE "FileA.txt"', securing data integrity and releasing resources .

You might also like