Show Menu
Cheatography

To help with coding in pseudo

variables

num = 44           //assignments
const k=34.56      //constants
global lives = 3   //global

input/­output

pwd = input(“Please enter a password”)   //input
print(“You have logged in succesfully”)  //output

casting

str(127)        //to string
int("45")       //to integer
float("7.45")   //to float
real(92.34)     //to real
bool("False")   //to boolean

commenting

// interesting comment
// another interesting comment

selection

//IF-THEN-ELSE
if hour < 12 then
    print(“Good Morning!”)
elseif (hour < 18) then
    print(“Good Afternoon!”)
else
    print(“Good Evening!”)
endif

//SWITCH
switch day:
    case 6:
        print(“Saturday”)
    case 7:
        print(“Sunday”)
    default:
        print(“Weekday”)
endswitch
 

Iteration

//FOR LOOP
for i = 0 to 9
    print (“i = ” + i)
next i

//WHILE LOOP
while password != “Password123”
    password = input(“Guess again”)
endwhile

//DO WHILE LOOP
do
    password = input(“Guess again”)
while password != “Password123”

random numbers

i = random(1,9)
r = random(1.1, 7.5)

file handling

f = open(“data.txt”)     //open
f.close()                //close
f.readLine()             //read line
f.writeLine(“Hello”)     //write line
while NOT f.endOfFile()
    print f.readLine()
endwhile                 //end of file
newFile(“newdata.txt”)   //create new file

arrays

array scores[5]  //declaration
score [0] = 23   //assignment
len(score)       //length
 

sub programs

//PROCEDURE
procedure sum(n1,n2)
    print(n1 + n2)
endprocedure

//FUNCTION
function sum(n1,n2)
    return(n1 + n2)
endfunction

//CALL A PROCEDURE
sum(8,9)

//CALL A FUNCTION
result = sum(8,9)

operators

//COMPARISON OPERATORS
myAge == 36         //equal
lives != 0          //not equal
health < 1          //less
score > 0           //greater
marks <= 40         //less or equal
marks >= 80         //greater or equal

//ARITHMETIC OPERATORS
4 + 5               //add
9 - 6               //subtract
2 * 4               //multiply
5 ^ 3               //exponent
6 / 3               //divide
7 MOD 2             //modulus
8 DIV 3             //quotient

//LOGICAL OPERATORS
age > 18 AND age < 60
hour < 9 OR hour > 17
NOT day == “Sunday”

//STRING OPERATORS
name.length         //string length
name.substring(2,4)
name.left(3)
name.right(5)      //substring
print("hi" + name) //concatenation
name.upper
name.lower         //case change
ASC(X)
CHR(75)            //ASCII conversation
                   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          common protocols and standards Cheat Sheet

          More Cheat Sheets by ghcytdckyc

          The subjunctive mood in French Cheat Sheet
          common protocols and standards Cheat Sheet