OCR Pseudocode Flashcards
Assigning global variables
global userid = 123
For Loops
for i=0 to 7 (inclusive)
print(“hello”)
next i
While loops
while answer != “”
answer = input()
endwhile
Do until loops
do
answer = input()
until answer == “”
if else statements
if entry == “a” then
print(“”)
elseif entry == “b” then
print(“”)
else
print(“”)
endif
Initiliasing an array called names with 5 items
array names[5]
Files
myFile = openRead(“text.txt”)
x = myFile.readLine()
myFile.close()
Printing every line in a file
while not myFile.endOfFile()
print(myFile.readLine())
endwhile
myFile.close()
An example class
class Dog inherits Pet
private breed
public procedure new(pName, pBreed)
super.new(pName)
breed = pBreed
endprocedure
public function getBreed()
return breed
endfunction
endclass
Creating an instance of a class (object)
myDog = new Dog(“Bob”, “Pitbull”)
Example of an 8 by 8 2d array called board
array board[8,8]
Assigning [0,0] position in a 2d array
board[0,0] = “rook”