You are on page 1of 1

KnowItAll

OCR ERL Cheatsheet Ninja


Commenting Casting Operators

Comment To String Comparison Operators Arithmetic Operators

//my note to me str(36) myAge == 36 //equal 4 + 5 //add


lives != 0 //not equal 9 - 6 //subtract
To Integer health < 1 //less 2 * 4 //multiply
Variables int(“13”) score > 0 //greater 5 ^ 3 //exponent
marks <= 40 //less or 6 / 3 //divide
Assignment 7 MOD 2 //modulus
To Float equal
myAge = 36 marks >= 80 //greater 8 DIV 3 //quotient
float(“3.14”) or equal
Constants To Real Logical Operators

const pi = 3.14 real(“3.14”) age > 18 AND age < 60


hour < 9 OR hour > 17
Global Variables To Bool NOT day == “Sunday”
global lives = 3 bool(“True”)
String Operations Arrays
Input/Output Declaration
String Length
Input array score[5]
name.length
pwd = input(“Please enter a password”) array ages[“Dan”,“Ali”]
Substrings array users[4, 4]
Output name.substring(2, 4) Assignment
name.left(3)
print(“You have logged in succesfully”) score[0] = 59
name.right(5)
users[1,3] = “Ninja01”
Concatenation
Selection
print(“Hi” + name) Length
If-Then-Else len(score)
Change Case
if hour < 12 then
name.upper
print(“Good Morning!”)
name.lower Random Numbers
elseif (hour < 18) then
print(“Good Afternoon!”) ASCII Conversion Random Numbers
else
print(“Good Evening!”) ASC(X) i = random(1,9)
endif CHR(75) r = random(1.1, 7.5)

Switch
File Handling
switch day:
case 6: Open Close
print(“Saturday”)
case 7: f = open(“data.txt”) f.close()
print(“Sunday”)
Read Line Write Line
default:
print(“Weekday”) f.readLine() f.writeLine(“Hello”)
endswitch
End of File

Iteration while NOT f.endOfFile()


print f.readLine()
FOR Loop endwhile

for i = 0 to 9 Create a New File


print (“i = ” + i)
newFile(“newdata.txt”)
next i

WHILE Loop
Sub Programs
while password != “Password123”
Procedure Function
password = input(“Guess again”)
endwhile procedure sum(n1,n2) function sum(n1,n2)
print(n1 + n2) return(n1 + n2)
DO WHILE Loop endprocedure endfunction
do
Call a Procedure Call a Function
password = input(“Guess again”)
while password != “Password123” sum(8,9) result = sum(8,9)

You might also like