Pseudocode Basics
Pseudocode Basics
An Introduction
Flowcharts were the first design tool to be
widely used, but unfortunately they do not
reflect some of the concepts of structured
programming very well. Pseudocode, on the
other hand, is a newer tool and has features
that make it more reflective of the structured
concepts. The drawback is that the narrative
presentation is not as easy to understand
and/or follow.
Rules for Pseudocode
Pseudocode
READ name, hoursWorked, payRate
gross = hoursWorked * payRate
WRITE name, hoursWorked, gross
Indent to Show Hierarchy
Each design structure uses a particular indentation
pattern
Sequence:
Keep statements in sequence all starting in the same column
Selection:
Indent statements that fall inside selection structure, but not the keywords that form the
selection
Loop:
Indent statements that fall inside 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
End Multiline Structures
READ name, grossPay, taxes
IF taxes > 0
net = grossPay taxes
ELSE
net = grossPay
ENDIF
WRITE name, net
yes no
amount < 100
Pseudocode ELSE
Interest Rate = .10
ENDIF
The Looping Structure
count
Mainline
<10
Modular
count = 0
Write WHILE count < 10
add 1 to The End
count DO Process
ENDWHILE
Stop
write count WRITE The End
Process
ADD 1 to count
WRITE count
REPEAT / UNTIL
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
Advantages & Disadvantages