Pseudocode Structure Flashcards
Variable assignment
var ← exp
One-dimensional array assignment
var[iexp] ← exp
Two-dimensional array assignment
var[iexp1][iexp2] ← exp
What number does indexing start at in Pseudocode?
1
Array initialisation of n elements
var ← [exp1, exp2, … , expn]
Conditional branching
IF bexp THEN statements ELSE statements ENDIF
Conditional execution (no branching)
IF bexp THEN
statements
ENDIF
Multi-branching conditional with n choices
CASE exp OF exp1: statements ... expn: statements ELSE statements ENDCASE
While loop
WHILE bexp
statements
ENDWHILE
For loop
FOR var ← iexp1 TO iexp2
statements
ENDFOR
Repeat/until loop
REPEAT
statements
UNTIL bexp
How many times does each loop run?
While: Zero or more times
For: A specific number of times
Repeat/until: At least once
In a Pseudocode for loop, where does the count variable have scope?
Only within the for loop
One line comment
comment
Function definition with n (possibly no) parameters
FUNCTION fname(param1, … , paramn)
statements
RETURN exp
ENDFUNCTION
Return statement
RETURN exp
Procedure definition with n (possibly no) parameters
PROCEDURE pname(param1, … , paramn)
statements
ENDPROCEDURE
Calling a subroutine with identifier name with n parameters
name(param1, … , paramn)
Modulo operator
iexp1 MOD iexp2
Binary boolean operators
AND, OR and XOR
Unary boolean operators
NOT
Length function
LEN(var)
Opens a file to read or write
OPEN filename to read/write
Returns the nth line of an external file
READLINE(file, n)
Writes (over) the nth line of an external file with value
WRITELINE(file, n, value)
Goes through a file until the end
WHILE NOT eof(filename) …
*eof = End Of File
Closes a file
CLOSE filename
Writes message to output
OUTPUT message
Gets the user’s input
USERINPUT
An integer expression
iexp
A boolean expression
bexp
A series of one line statements. A statement is terminated by a new line
statements