Session 9 - Pseudocode
Session 9 - Pseudocode
PSEUDOCODE
9.1 Introduction
9.8 Summary
9.9 Activity
9.1 Introduction
For looping and selection, the keywords that are to be used include Do
While...EndDo; Do Until...Enddo; Case...EndCase; If...Endif; Call ... with
(parameters); Call; Return ....; Return; When; Always use scope terminators
for loops and iteration. As verbs, use the words Generate, Compute, Process,
etc. Words such as set, reset, increment, compute, calculate, add, sum,
multiply, ... print, display, input, output, edit, test, etc. with careful
indentation tend to foster desirable pseudocode. Do not include data
declarations in your pseudocode.
The following examples shows some keywords that can be used while writing
a pseudocode:
Print "passed"
else
Print "failed"
else
else
ii. Ease up code construction. When the programmer goes through the
process of developing and generating pseudocode, the process of
converting that into real code written in any programming language will
become much easier and faster as well.
iii. A good middle point between flowchart and code. Moving directly
from the idea to the flowchart to the code is not always a smooth ride.
That’s where pseudocode presents a way to make the transition
between the different stages somewhat smoother.
ii. Start with the statement of a pseudo code which establishes the main
goal or the aim.
Example:
This program will allow the user to check the number whether it's even
or odd.
iii. The way the if-else, for, while loops are indented in a program, indent
the statements likewise, as it helps to comprehend the decision control
and execution mechanism. They also improve the readability to a great
extent.
Example:
if "1"
print response
if "2"
print response
iv. Use appropriate naming conventions. The human tendency follows the
approach to follow what we see. If a programmer goes through a pseudo
code, his approach will be the same as per it, so the naming must be
simple and distinct.
vi. Elaborate everything which is going to happen in the actual code. Don’t
make the pseudo code abstract.
vii. Use standard programming structures such as ‘if-then’, ‘for’, ‘while’,
‘cases’ the way we use it in programming.
viii. Check whether all the sections of a pseudo code are complete, finite and
clear to understand and comprehend.
Solution:Pseudocode
Start Program
Enter two numbers, A, B
Add the numbers together
Print Sum
End Program
In this session we have learnt about pseudocode and the role they play in
problem solving. Next session, we will discuss about flowcharts.
9.9 Activity