SlideShare a Scribd company logo
1 of 13
Pseudocode

       For
 Program Design


                  1
Flowcharts vs Pseudocode
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.
                                                   2
Rules for Pseudocode
Write only one statement per line
Capitalise initial keyword
Indent to show hierarchy and structures
End multiline structures
Keep statements language independent
  Remember you are describing a logic plan to develop
  a program, you are not programming!



                                                        3
One Statement Per Line
Each statement in pseudocode should express
just one action for the computer.
  Note capitals for the initial keywords
                    Pseudocode
         READ name, hoursWorked, payRate
         gross = hoursWorked * payRate
         WRITE name, hoursWorked, gross

These are just a few of the keywords to use,
others include
  READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE
                                                  4
Indent to Show Hierarchy
Sequence:
  Keep statements in sequence all starting in the same column
Selection:                             READ name, grossPay, taxes
                                       IF taxes > 0
  IF, ELSE (or ELSEIF), ENDIF
                                            net = grossPay – taxes
  must be in line
                                       ELSE
  Indent all statements that depend       net = grossPay
  on a condition                       ENDIF
Loop:                                  WRITE name, net
                                       count = 0
  WHILE, ENDWHILE
                                       WHILE count < 10
  Indent statements that fall inside       ADD 1 to count
  the loop but not keywords that          WRITE count
  form the loop                        ENDWHILE
  Also REPEAT, UNTIL                   WRITE “The End”
                                                                     5
The Selection Structure

             yes                    no
                     amount < 100




interestRate = .06                   interestRate = .10




                                                  IF amount < 100
                                                      interestRate = .06
                          Pseudocode             ELSE
                                                     InterestRate = .10
                                                  ENDIF

                                                                           6
The Looping Structure
In flowcharting one of the more confusing things
is to separate selection from looping. This is
because each structure use the diamond as their
control symbol.
Pseudocode avoids this by using specific
keywords to designate looping
  WHILE / ENDWHILE: condition checked before loop
  REPEAT / UNTIL: condition checked after loop



                                                    7
WHILE / ENDWHILE
   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     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
                                                           8
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
                                                      9
Flowchart vs Pseudocode
Flowchart Advantages:          Pseudocode Advantages
  Standardized                   Easily modified
  Visual                         Implements structured
                                 concepts
                                 Done easily on Word
                                 Processor

Flowchart Disadvantages:       Pseudocode
  Hard to modify               Disadvantages:
  Structured design elements     Not visual
  not implemented                No accepted standard, varies
  Special software required      from company to company

                                                                10
Access of Data
The READ statement tells the computer to get a
value from an input device and store it in a memory
location.
  How to deal with memory locations which have been
  allocated an address e.g. 19087
Give them names (field or variable names)
  Using descriptive words e.g. Total as opposed to a
  location addresses




                                                       11
Rules for Variable Names
Begin with lowercase letter
Contain no spaces
Additional words begin with capital
Unique names within code
Consistent use of names




                                      12
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




                                                         13

More Related Content

What's hot

Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigmbusyking03
 
Algorithm Design & Implementation
Algorithm Design & ImplementationAlgorithm Design & Implementation
Algorithm Design & ImplementationGaditek
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart exampleshayrikk
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
 
Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchartlotlot
 
SPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and FlowchartSPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and FlowchartMohammad Imam Hossain
 
Algorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesAlgorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesSatveer Mann
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativityDr.Sandhiya Ravi
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithemehsanullah786
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using ComputerDavid Livingston J
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programmingChaffey College
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentationMartin McBride
 

What's hot (20)

Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
 
Algorithm Design & Implementation
Algorithm Design & ImplementationAlgorithm Design & Implementation
Algorithm Design & Implementation
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart examples
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Identifiers
Identifiers Identifiers
Identifiers
 
Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
 
SPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and FlowchartSPL 2 | Algorithms, Pseudo-code, and Flowchart
SPL 2 | Algorithms, Pseudo-code, and Flowchart
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Algorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodesAlgorithms, flow charts and pseudocodes
Algorithms, flow charts and pseudocodes
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithem
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using Computer
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 

More from nicky_walters (20)

Design documentation
Design documentationDesign documentation
Design documentation
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Software development lifecycle
Software development lifecycleSoftware development lifecycle
Software development lifecycle
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Design for edp
Design for edpDesign for edp
Design for edp
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Event driventheory
Event driventheoryEvent driventheory
Event driventheory
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Debugging
DebuggingDebugging
Debugging
 
Using loops
Using loopsUsing loops
Using loops
 
Input output
Input outputInput output
Input output
 
Decisions
DecisionsDecisions
Decisions
 
Decisions
DecisionsDecisions
Decisions
 
Controls
ControlsControls
Controls
 
Decisions
DecisionsDecisions
Decisions
 

Pseudocode flowcharts

  • 1. Pseudocode For Program Design 1
  • 2. Flowcharts vs Pseudocode 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. 2
  • 3. Rules for Pseudocode Write only one statement per line Capitalise initial keyword Indent to show hierarchy and structures End multiline structures Keep statements language independent Remember you are describing a logic plan to develop a program, you are not programming! 3
  • 4. One Statement Per Line Each statement in pseudocode should express just one action for the computer. Note capitals for the initial keywords Pseudocode READ name, hoursWorked, payRate gross = hoursWorked * payRate WRITE name, hoursWorked, gross These are just a few of the keywords to use, others include READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE 4
  • 5. Indent to Show Hierarchy Sequence: Keep statements in sequence all starting in the same column Selection: READ name, grossPay, taxes IF taxes > 0 IF, ELSE (or ELSEIF), ENDIF net = grossPay – taxes must be in line ELSE Indent all statements that depend net = grossPay on a condition ENDIF Loop: WRITE name, net count = 0 WHILE, ENDWHILE WHILE count < 10 Indent statements that fall inside ADD 1 to count the loop but not keywords that WRITE count form the loop ENDWHILE Also REPEAT, UNTIL WRITE “The End” 5
  • 6. The Selection Structure yes no amount < 100 interestRate = .06 interestRate = .10 IF amount < 100 interestRate = .06 Pseudocode  ELSE InterestRate = .10 ENDIF 6
  • 7. The Looping Structure In flowcharting one of the more confusing things is to separate selection from looping. This is because each structure use the diamond as their control symbol. Pseudocode avoids this by using specific keywords to designate looping WHILE / ENDWHILE: condition checked before loop REPEAT / UNTIL: condition checked after loop 7
  • 8. WHILE / ENDWHILE 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 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 8
  • 9. 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 9
  • 10. Flowchart vs Pseudocode Flowchart Advantages: Pseudocode Advantages Standardized Easily modified Visual Implements structured concepts Done easily on Word Processor Flowchart Disadvantages: Pseudocode Hard to modify Disadvantages: Structured design elements Not visual not implemented No accepted standard, varies Special software required from company to company 10
  • 11. Access of Data The READ statement tells the computer to get a value from an input device and store it in a memory location. How to deal with memory locations which have been allocated an address e.g. 19087 Give them names (field or variable names) Using descriptive words e.g. Total as opposed to a location addresses 11
  • 12. Rules for Variable Names Begin with lowercase letter Contain no spaces Additional words begin with capital Unique names within code Consistent use of names 12
  • 13. 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 13