











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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.