This document provides an introduction to pseudocode and discusses its advantages over flowcharts. It outlines some basic rules for writing pseudocode, such as writing one statement per line and capitalizing keywords. It also covers pseudocode structures like sequence, selection, and looping. Pseudocode is presented as being more reflective of structured programming concepts compared to flowcharts, though it may be less visually clear. The document provides examples of pseudocode for common programming structures.
2. Flowcharts were the firs t des ign tool to
be widely us ed, but unfortunately they do
not reflect s ome of the c oncepts of
s tructured programming very well.
Ps eudocode, on the other hand, is a
newer tool and has features that make it
more reflective of the s truc tured
concepts . The drawback is that the
narrative pres entation is not as eas y to
unders tand and/or follow.
3. Rules for Ps eudocode
• Write only one s tatement per line
• C apitalize initial keyword
• Indent to s how hierarc hy
• E nd multiline s tructures
• Keep s tatements language
independent
4. One S tatement Per Line
E ach s tatement in ps eudocode s hould
expres s jus t one action for the computer.
If the tas k lis t is properly drawn, then in
mos t cas es each tas k will corres pond to
one line of ps eudocode.
Task List Pseudocode
Read name, hours worked, rate of pay READ name, hoursWorked, payRate
Perform calculations gross = hoursWorked * payRate
gross = hours worked * rate of pay WRITE name, hoursWorked, gross
Write name, hours worked, gross
5. C apitalize Initial Keyword
In the example below note the words : RE A D and
WRITE . Thes e are jus t a few of the keywords to
us e, others include:
RE A D, WRITE , IF, E LS E , E NDIF, WHILE , E NDWHILE
Pseudocode
READ name, hoursWorked, payRate
gross = hoursWorked * payRate
WRITE name, hoursWorked, gross
6. Indent to S how Hierarchy
E ch design stuct e uses apat a indent t pat n
a r ur ricul r aion ter
• S equence:
Keep s tatements in s equence all s tarting in the s ame column
• S election:
Indent s tatements that fall ins ide s election s tructure, but not the keywords that
form the s election
• Loop:
Indent s tatements that fall ins ide the loop but not keywords that form the loop
READ name, grossPay, taxes
IF taxes > 0
net = grossPay – taxes
ELSE
net = grossPay
ENDIF
WRITE name, net
7. E nd Multiline S tructures
READ name, grossPay, taxes
IF taxes > 0
net = grossPay – taxes
ELSE
net = grossPay
ENDIF
WRITE name, net
S ee the IF/E LS E /E NDIF as cons tructed
above, the E NDIF is in line with the IF.
The s ame applies for WHILE /E NDWHILE
etc…
8. Language Independence
Res is t the urge to write in whatever language you
are mos t comfortable with, in the long run you
will s ave time. Remember you are des cribing a
logic plan to develop a program, you are not
programming!
9. T Sel ion St uct e
he ect r ur
yes no
amount < 100
interestRate = .06 interestRate = .10
IF amount < 100
interestRate = .06
Pseudocode ELSE
Interest Rate = .10
ENDIF
10. T L
he oopingSt uct e
r ur
In flowcharting one of the more confus ing
things is to s eparate s election from
looping. This is becaus e each s tructure
us e the diamond as their control s ymbol.
In ps eudocode we avoid this by us ing
s pecific keywords to des ignate looping
WHILE /E NDWHILE
RE PE A T/UNTIL
11. W E/E HIL
HIL NDW E
Start
count = 0
WHILE count < 10
ADD 1 to count
count = 0
WRITE count
ENDWHILE
WRITE “The End”
count
Mainline
<10
Modular
count = 0
Write
“The End”
WHILE count < 10
add 1 to
count DO Process
ENDWHILE
Stop
write count WRITE “The End”
Process
ADD 1 to count
WRITE count
12. R PE T/UNT
E A IL
Start count = 0
REPEAT
count = 0
ADD 1 to count
WRITE count
UNTIL count >= 10
add 1 to WRITE “The End”
count
Mainline
Modular
write count count = 0
REPEAT
DO Process
count
<10 UNTIL count >= 10
WRITE “The End”
Write Process
“The End”
ADD 1 to count
Stop WRITE count
13. A a a &Disa a a
dv nt ges dv nt ges
Flowchart Advantages: Pseudocode Advantages
Standardized Easily modified
Visual Implements structured
concepts
Done easily on Word
Processor
Flowchart Disadvantages: Pseudocode Disadvantages:
Hard to modify Not visual
Structured design elements not No accepted standard, varies from
implemented company to company
Special software required
14. A ofDaa
ccess t
T R A st t
he E D aementt l t comput t getav l fr a inputdev a st e itin a
els he er o aue om n ice nd or
memor l t
y ocaion.
Howt dea w h memor l t
o l it y ocaions?
Memory locations are identified by their addresses, we
give them names (field names / variable names) using
words descriptive to us such as ctr as opposed to a
location addresses such as 19087.
15. Rules for Variable Names
• Begin with lowercase letter
• Contain no spaces
• Additional words begin with capital
• Unique names within code
• Consistent use of names
16. Working with Fields
Calculations Selection
+ add > greater than
- subtract < less than
* multiply = equal to
/ divide >= greater than or equal to
** or ^ exponentiation <= less than or equal to
() grouping <> not equal to