Professional Documents
Culture Documents
Pseudo Code Slides
Pseudo Code Slides
Pseudo Code Slides
2
Objectives
Variable
Output/Inputs
Sequence
Selection
Iteration
Flowcharts
3
Why we use Pseudo Code
• Syntactical Representation of a program
• It helps no programmers understand programming logic
• Debug and solve problems without actually writing a code
Variables
Variables are assigned using the = operator.
x=3
name=”Bob”
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
** Exponent a**b
== Equal to a==b
The logical operators are the and, or, and not operators. or True if either operand x or y
is true.
& AND If both bits are 1, this function sets each bit to 1.
| OR If one of two bits is 1, each bit is set to 1.
^ XOR If only one of two bits is 1, this function sets each bit to 1.
~ NOT All the bits are inverted.
<< Bitwise left shift Shift left by pushing zeros in from the right and letting the
bits on the left fall off.
>> bitwise right shift Shift right by copying the leftmost bit from the left and
letting the rightmost bits fall off.
How to write pseudo code
1.Arrange the sequence of tasks and write the pseudocode accordingly.
2.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.
15
How to write pseudo code
1.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 readability
to a great extent.
Example:
if "1"
print response
"I am case 1"
if "2"
print response
"I am case 2"
16
How to write pseudo code
• 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.
• Use appropriate sentence casings, such as CamelCase for methods,
upper case for constants a,nd lower case for variables.
• Elaborate on everything which is going to happen in the actual code.
Don’t make the pseudo code abstract.
17
How to write pseudo code
• Use standard programming structures such as ‘if-then’, ‘for’, ‘while’,
and ‘cases’ the way we use it in programming.
• Check whether all the sections of a pseudo code is complete, finite,
and clear to understand and comprehend.
• Don’t write the pseudo-code in a complete programmatic manner. It is
necessary to be simple to understand even for a layman or client,
hence don’t incorporate too many technical terms.
18
Examples
If a student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"
19
Examples
Set the total to zero
Set grade counter to one
While the grade counter is less than or equal to ten
Input the next grade
Add the grade to the total
Set the class average to the total divided by ten
Print the class average.
20
Examples
21
Flow charts
22