0% found this document useful (0 votes)
7 views2 pages

Mason Pseudocode

This document is a cheat sheet for pseudocode, outlining data types, constructs, operators, and file handling. It provides examples of control structures like IF, FOR, WHILE, and functions, along with string manipulation techniques. The cheat sheet emphasizes the importance of proper syntax and understanding of programming concepts rather than strict adherence to a specific programming language's syntax.

Uploaded by

chary song
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Mason Pseudocode

This document is a cheat sheet for pseudocode, outlining data types, constructs, operators, and file handling. It provides examples of control structures like IF, FOR, WHILE, and functions, along with string manipulation techniques. The cheat sheet emphasizes the importance of proper syntax and understanding of programming concepts rather than strict adherence to a specific programming language's syntax.

Uploaded by

chary song
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PseudoCode Cheat Sheet

by mason via cheatography.com/35063/cs/11011/

Data Types Constructs For

STRING IF condition THEN FOR i = 1 to 10


INTEGER ​ ​ ​ do something ​ ​ ​ ​sta​tements
ELSE NEXT i
REAL
​ ​ ​ do something else END FOR
BOOLEAN
END IF
With a FOR loop, increm​enting and initia​‐
CHARACTER
WHILE condition lizing of the counting variable are done
​ ​ ​ ​sta​tements automa​tically
Arithmetic Operators
END WHILE You can call the counting variable (i, in this
Addition: + Division: / REPEAT case) anything you want, and you can also
Subtra​ction: – Remainder: MOD ​ ​ ​ ​sta​tements set the = something TO something values
Multip​lic​ation: * Integer Division: DIV UNTIL condition to whatever you want it to count from and to

The else bit is optional – you don’t have to


Other Relational / Comparison Operators
have it
Assignment operator: = Don’t confuse = The condition is any expression that Equal to: == Not equal to: !=
with == (they’re different) evaluates to a Boolean Not equal to: <> Greater than: >
You can use true and false to check Notice how the statements are indented
Less than: < Greater than or equal
Boolean variables in your conditions (as in (well, hopefully they’ll display indented
to: >=
IF SomeBo​ole​anV​ariable == true THEN … when I publish this…)
Less than or equal Both: AND
etc.) When using WHILE and REPEAT loops, to
to: <=
count, you need to manually initialize and
Variables are not loosely typed – you can’t
increment the counting variable One or both: OR Invert: NOT
mix different types of variable They don’t
The statements inside a loop should cause Logical / Boolean Operators
seem to have to be declared, although
a change in one of the values in the
sometimes there’ll be a declar​ation (If you’re
condition, otherwise you may create an CASE
asked to declare something, you can pretty
infinite loop
much just make it up – as long as it CASE OF something
specifies the data type, identi​fier, etc…) ​ ​ ​ ​som​ething = this:
Procedure & Functions
Sometimes a colon is used to identify the statement
PROCEDURE doSomething(Parameter
data type of a variable, e.g. SomeVa​riable : ​ ​ ​ ​som​ething = that:
: DATATYPE, OtherParameter:
REAL would declare a real (decimal) statement
variable DATATYPE)
​ ​ ​ ​som​ething = other:
​ ​ ​ ​sta​tements
Keywords are in capitals in pseudocode statement
END PROCEDURE
Arrays work as they do in most languages, ​ ​ ​ ​def​ault: statement
FUNCTION doSome​thi​ng(​par​‐
but often their index starts at 1, rather than END CASE
ameter: DATATYPE) : RETURNTYPE
0, and sometimes they use parent​hesis ( ) In a case statement (that’s switch statement
​ ​ ​ ​sta​tements
instead of brackets [ ] to Java/C# people) you can have however
RETURN something
Multid​ime​nsional arrays work like this: many options you want, but there must
END PROCEDURE
identi​fier(y, x) always be a default for if none of the options
Procedures and functions don’t have to take match
parame​ters, but the parent​heses () are In the example above, something is the
necessary variable that is being checked, and this, that
Functions must have a return type and and other are things it’s being compared
must return something (of that type) with
File Handling

By mason Not published yet. Sponsored by ApolloPad.com


cheatography.com/mason/ Last updated 26th February, 2017. Everyone has a novel in them. Finish
Page 1 of 2. Yours!
https://apollopad.com
PseudoCode Cheat Sheet
by mason via cheatography.com/35063/cs/11011/

String Manipu​lation File Handling

There are two functions that look things up OPEN filename (You can open as
in the ASCII character set table for you: FOR MODE READ or WRITE only,
ASCII(​cha​racter) returns the ASCII value of one at a time)
a character, character READ extrac​ted​‐ WRITE something TO
CHAR(i​nteger) returns the character of an var​iable FROM filename
ASCII value, integer filename

Characters may be in single or double CLOSE filename DELETE filename


quotes (it’s another thing the examiners RENAME CREATE filename
don’t seem to have made their minds up filename TO
about) something
Strings can be concat​enated using the “filename is at end of file” can be used in
addition operator, + the condition of loops, to iterate through all
You sometimes have to use concat​enation the records
to output something in a friendly way
High-Level Questions
Mathem​atics can’t be done on strings, but
you can compare their ASCII values using
the relational operators (<, >, <>, !=, ==, >=, Occasi​onally, you’ll be asked to write
<=) something in a real language
MID(st​ring, integer1, integer2) returns the I think the course does require you to be
part of the string between positions integer1 taught the basics of a high-level procedural
and integer2 progra​mming language in the first year
Again, though, the questions are more
LEFT(s​tring, integer) RIGHT(​string, integer)
about unders​tanding what to do than
LENGTH​(st​ring) returns the length of the
following the correct syntax
string, string
Famili​arise yourself with how to write the
LOCATE​(st​ring1, string2) returns the
constructs above in a high-level language
position of the first occurrence of string2 in
(i.e. not assembly…)
string1 (0 means it starts at the beginning, -
1 means it’s not in there)
I don’t know why these functions are acting
like there are official pseudocode libraries…
they must just be for inspir​ation, and as a
guide

By mason Not published yet. Sponsored by ApolloPad.com


cheatography.com/mason/ Last updated 26th February, 2017. Everyone has a novel in them. Finish
Page 2 of 2. Yours!
https://apollopad.com

You might also like