Pseudocode Flashcards
Write code to display output on a screen
OUTPUT A
Write code to perform string operations (length)
LEN(‘StringExp’)
LEN(‘computer science’)
= 16 (including spaces)
Write code to find position of char in string
POSITION (‘StringExp’ , ‘CharExp’)
POSITION(‘computer science’, ‘m’
= 2 (indexing starts at 0)
Write code to perform string operations (substring)
SUBSTRING(IntExp, IntExp, ‘StringExp’)
SUBSTRING(2, 9, ‘computer science’)
= ‘mputer s’
Write code to perform string operations (concatenation)
StringExp + StringExp
‘Computer’ + ‘Science’
= ‘computerscience’
Converting string to integer
STRING_TO_INT(StringExp)
Converting string to real
STRING_TO_REAL(StringExp)
Converting integer to string
INT_TO_STRING(IntExp)
Converting real to string
REAL_TO_STRING(RealExp)
Converting character to character code
CHAR_TO_CODE(CharExp)
Converting character code to character
CODE_TO_CHAR(IntExp)
Integer Division
IntExp DIV IntExp
Count controlled iteration (For loop)
FOR Identifier arrow IntExp TO IntExp STEP IntExp
ENDFOR
Condition controlled iteration (While)
WHILE BoolExp
#statements
ENDWHILE
If/elseif/else structure
IF BoolExp THEN #S ELSE IF BoolExp THEN #S ELSE #S ENDIF
Assigning array
Identifier arrow [IntExp]
Assigning 2D array
Identifier arrow [IntExp][IntExp]
Updating element in array
Identifier [IntExp] arrow Exp
Find Array length
LEN(Identifier)
For loop for length of array
FOR identifier IN array
#statements (identifier can be used as a local
variable here (eg. i)
ENDFOR
Declaring a record
RECORD Record_identifier field1 : datatype field2 : datatype … ENDRECORD
Declaring variable with record
VarName arrow Record_identifier(value1,value2,…)
Assigning a value to a field in a record
VarName.field arrow Exp
Accessing values of files in records
VarName.field
how to write Subroutine
SUBROUTINE identifier (parameters) # statements ENDSUBROUTINE
Return value in subroutine
RETURN Exp
Calling subroutines
Identifier (parameters)
Generate random number
Identifier arrow RANDOM_INT(StartValue, EndValue)
This function is inclusive