Topic 2
Topic 2
Topic 2
The words and symbols that make up a programming language are known as its
syntax.
C#, Java, C , Visual Basic and so on all have their own particular syntax.
In exactly the same way, the pseudocode we develop during this module will have
its own syntax.
It’s just that we won’t be able to compile it into real computer code.
Why Pseudocode?
When we need to display anything to the user, we use output. Enclose what’s
seen by the user in quotation marks.
Output “Hello there!”
If we need to output the contents of some data, we also use output but omit the
quotation marks:
Output myAge
We can put information in a data container like so:
myAge = 20
Pseudocode Syntax
Arithmetic Operators
Naming Convention (Camel case)
It is the practice of writing compound words or phrases such that each word or
abbreviation in the middle of the phrase begins with a capital letter , with no spaces or
hyphens.
Camel case may start with a capital letter or with a lowercase letter.
Examples
iPhone
FedEx
HarperCollins
Pseudocode Example
3. myAge=10
4. myNewAge = myAge + 1
5. myNewAge = myAge + 1
5. myNewAge = myAge + 1
The code (or pseudocode) that we write defines the flow of execution through a
program.
This is the order in which code statements are executed when the program is
running.
So far, we have looked only at sequential flow of execution.
Each line of code is executed after the last.
In later weeks, we will look at ways of representing loops and choices.
These make desk-checking more challenging.
Desk-Checking
The full line of code is shown on the desk-check for easy reference.
An alternate, and easier, system is to provide line numbers.
For this, you will need to ensure that your pseudo-code programs contain line
numbers.
Number only lines that contain pseudocode statements.
Do not number blank lines
Pseudocode Example
1 data income as whole number
2 data taxRate as real number
3 data myTax as real number
4 data myNetPay as real number
7 taxRate = 10.00
8 myTax = income * taxRate
9 myNetPay = income - taxRate
Before After
The two main commenting styles in most languages are line-by-line or block comments. You can
use either of these for your pseudocode.
// This is a comment /*
And so is this!
*/
Line Block
Commenting
/* /*
The following algorithm calculates the The following algorithm takes one value
length of the hypotenuse of a right and squares it and then takes another
angled triangle. value and squares it. It then gives
*/ the square root of the sum of those
squares.
*/
A comment should explain to people what you were doing, not how you were doing it. The
code itself will do the latter if it’s well written (more on that later).
Commenting
1 data income as whole number
2 data taxRate as real number
3 data myTax as real number
4 data myNetPay as real number
// Taking input from User
5 output "What is your annual salary?"
6 input income
/* Calculating Tax rate
and myNetPay */
7 taxRate = 10.00
8 myTax = income * taxRate
9 myNetPay = income - taxRate