











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A proper guide of how to write pseudo code in o levels exams.
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












Pseudocode
Storage
VariableConstant
Array
I/O
INPUT PRINT
Selection
IF
āTHEN CASE
āOF
Repetition
Counter
FOR
āNEXT
Conditional
WHILE
ā
END
WHILE REPEAT
ā
UNTIL
Following the common data types that are used in pseudocode when declaring variables, constants and arrays. Some data types can be referred with more than one name; alternative names are also listed.
INTEGER Data type to hold whole numbers i.e. numbers without decimal value. It contains both positive and negative numbers ļ Example: 56 , 27 , ā ļŖ Use: Mainly used for counting, whole number addition/subtraction etc.
Data type to hold floating point numbers i.e. numbers with decimal value. It contains both positive and negative decimal numbers ļ Example: 72.84 , 0.014 , ā12. ļŖ Use: Mainly used for money, weight, height, temperature etc.
Data type to hold a āsingleā alphanumeric character. ļ Example: R , K , s ļŖ Use: Mainly used for codes like T or F (True/False), M or F(male/female) etc.
Data type to hold alphanumeric characters. It includes all printable characters including alphabets, numbers, special symbols and punctuation marks. ļ Example: Google , CIE2016 , R@N# ļŖ Use: Mainly used for names, address etc.
SET array_name [1:max] AS datatype SET array_name [max] AS datatype Where: array_name is the name of array. It can be anything but should be meaningful and signify the purpose. Array names should start with an alphabet. 4num is not a valid array name since it starts with a number. datatype is the data type of array. It could be integer, float, char or string. max is the size of an array. It is the number of elements in an array. ļ Example ļ§ SET marks [1:10] AS Integer ļ§ SET father names [50] AS String ļ± Beware ļ§ An arrayās index number cannot be a floating point value nor it can be negative value. It can only be a positive integer value.
Values can be assigned to variables, constants and arrays at either declaration or afterwards in
always assigned to the variable that is on the left hand side, hence the direction of the arrow will ALWAYS be towards the left hand side.
VARIABLES variable_name ļ¬ Value variable_name ļ¬ another_variable
Where: variable_name is the name of variable that has been already declared. Value is the data to assigned to variable. It should match with the data type of variable. String / Text values are always enclosed in double quotes ( ā ā ) and Char values are enclosed in single quotes ( ā ā ). Integer & float values are directly assigned. another_variable is some other variable containing a value.
ļ Example
ļ± Beware ļ§ Always assign values to variables according to its data type. Assigning text data to a variable that is declared as Integer is wrong and may lose marks in exams.
Taking user input is done using INPUT keyword and output is printed using PRINT keyword. Input can only be stored in either variable or array. Output can be displayed from variables, arrays, constants and fixed values (string literals).
INPUT INPUT variable_name INPUT array_name [index]
Where: variable_name is the name of variable in which to store the input. array_name is the name of array in which to store the input. Index is the particular element/location in an array
ļ Example
ļŖ Important
with comma_. (see above example; last one)_
ļ± Beware
and cannot be changed anywhere in pseudocode.
use loop to fill array since it is a collection of variables.
PRINT variable_name PRINT array_name [index] PRINT āstring_literalā Where: variable_name is the name of variable to be printed. array_name is the name of an array to be printed. Index is the particular element/location in an array string_literal is a fixed text value to be printed. For example a message like āThe answer isā.
ļ Example
ļŖ Important
them with comma_. (see above example; last one)_
ļ± Beware
to use loop to print array since it is a collection of variables
IF ā THEN ā ELSE (Multiple conditions)
IF condition THEN Instructions ELSE IF condition THEN Instructions END IF
Where: condition is the condition to evaluate. Its answer will always be in the form of True or False. instructions are the pseudocode statements that will only be executed if the condition evaluates to true. In simple words, these lines of code will only run if the conditionās answer is True otherwise they will not run and computer will directly jump to line after END IF statement
ļ Example
PRINT āYou are underweightā ELSE IF weight < 35 THEN PRINT āYour weight is normal END IF
ELSE IF chocolate = ākokoā THEN
CASEāOF does the same thing as IFāTHEN but it is a bit more concise and clearer to read.
CASEāOF CASE variable OF Compare1: Instructions Compare2: Instructions END CASE Where: Variable is the variable which contains the value that you want to check for. Compare1-2 are the values which you compare with variable (defined with CASE command). There can be as many compare statements as you need to test. There is no limit. instructions are the pseudocode statements that will only be executed if the compare evaluates to true. In simple words, these lines of code will only run if the conditionās answer is True otherwise they will not run and computer will directly jump to line after END CASE statement
ļ Example
PRINT āYou are underweightā < 35: PRINT āYour weight is normal END CASE
āBabliā:
ākokoā:
ļ§ ļ± Beware
possible in FOR loop nor does it make any sense.
WHILE condition DO Instructions END WHILE Where: condition is the condition to check. If the result of comparison returns TRUE , only then the statements inside DO will be executed. instructions are the pseudocode statements that will only be executed if the comparison evaluates to true. In simple words, these lines of code will only run if the conditionās answer is True otherwise they will not run and computer will directly jump to line after END WHILE statement
ļ Example
PRINT āYou are overweightā END WHILE
ļŖ Important
checking condition is TRUE.
Instructions UNTIL condition Where: condition is the condition to check. If the result of comparison returns FALSE , only then the statements inside REPEAT will be executed. instructions are the pseudocode statements that will only be executed if the comparison evaluates to false. In simple words, these lines of code will only run if the conditionās answer is False otherwise they will not run and computer will directly jump to line after UNTIL statement
ļ Example
PRINT āYou are overweightā UNTIL weight < 120
ļŖ Important
checking condition is FALSE.
ļ· Repeat statements fixed number of times
ļ· Repeats statements when condition is true
ļ· Repeats statements when condition if false
ļ· No condition checking ļ·^ Checks start of^ conditionloop^ at^ the^ ļ·^ Checks of loop^ condition^ at^ the^ end
APPENDIX ā B
MATHEMATICAL OPERATORS
Following are the basic arithmetic operators that allow us to perform different types of mathematical calculations in our flowchart/pseudocode.
OPERATOR MEANING + Addition ā Subtraction ***** Multiplication / Division mod Remainder ā Assignment^ operator.^ Used^ to^ assign^ values^ to variables/constant/array.
COMPARISION OPERATORS
Comparison operators allows us to compare different values.
**OPERATOR MEANING
** Greater^ than < Less^ than > = Greater^ than^ or^ equal^ to < = Less^ than^ or^ equal^ to < > Not^ equal^ to = Equal^ to^ (In^ sense^ of^ comparison)
Two values can be compared using the above operators and the answer would be in the form of YES/TRUE or NO/FALSE. For example; if we say 5 > 7, then the answer would be NO/FALSE since 5 is not greater than 7.