Decision Tables and PseudocodeDecision Tables and Pseudocode
Rizwan Rehman
Asstt. Professor
Centre for Computer Studies
Decision Tables GeneralDecision Tables General
    Decision tables are precise yet compactway to model complicated logic. Decision tables,like if-then-else and switch-case statements,associate conditions with actions to perform.
But, unlike the control structures found intraditional programming languages, decisiontables can associate many independentconditions with several actions in an elegantway.
2
Decision Tables UsageDecision Tables Usage
Decision tables make it easier to observe that allpossible conditions are accounted for.
Decision tables can be used for:
Specifying complex program logic
Generating test cases (Also known as logic-based testing)
Logic-based testing is considered as:
structural testing when applied to structure (i.e. control flowgraph of an implementation).
functional testing when applied to a specification.
3
Decision Tables StructureDecision Tables Structure
Conditions - (Condition stub)
Condition Alternatives –(Condition Entry)
Actions – (Action Stub)
Action Entries
4
 Each condition corresponds to a variable, relation or predicate
 Possible values for conditions are listed among the condition
  alternatives
 Boolean values (True / False) – Limited Entry Decision Tables
 Several values – Extended Entry Decision Tables
 Don’t care value
 Each action is a procedure or operation to perform
 The entries specify whether (or in what order) the action is to be
   performed
To express the program logic we can use a limited-entrydecision table consisting of 4 areas called the conditionstub, condition entry, action stub and the action entry:
5
Rule1
Rule2
Rule3
Rule4
Condition1
Yes
Yes
No
No
Condition2
Yes
X
No
X
Condition3
No
Yes
No
X
Condition4
No
Yes
No
Yes
Action1
Yes
Yes
No
No
Action2
No
No
Yes
No
Action3
No
No
No
Yes
Condition
 stub
Action stub
Action Entry
Condition entry
We can specify default rules to indicate the action to betaken when none of the other rules apply.
 When using decision tables as a test tool, default rules andtheir associated predicates must be explicitly provided.
6
Rule5
Rule6
Rule7
Rule8
Condition1
X
No
Yes
Yes
Condition2
X
Yes
X
No
Condition3
Yes
X
No
No
Condition4
No
No
Yes
X
Defaultaction
Yes
Yes
Yes
Yes
Decision Table ExampleDecision Table Example
Conditions
Printer does not print
Y
Y
Y
Y
N
N
N
N
A red light is flashing
Y
Y
N
N
Y
Y
N
N
Printer is unrecognized
Y
N
Y
N
Y
N
Y
N
Actions
Heck the power cable
X
Check the printer-computer cable
X
X
Ensure printer software is installed
X
X
X
X
Check/replace ink
X
X
X
X
Check for paper jam
X
X
7
Printer Troubleshooting
PseudocodePseudocode
Flowcharts were the first design tool to bewidely used, but unfortunately they do notreflect some of the concepts of structuredprogramming very well.
 Pseudocode, on the other hand, is anewer tool and has features that make itmore reflective of the structuredconcepts.  The drawback is that thenarrative presentation is not as easy tounderstand and/or follow.
Rules for PseudocodeRules for Pseudocode
Write only one statement per line
Capitalize initial keyword
Indent to show hierarchy
End multiline structures
Keep statements languageindependent
One Statement Per LineOne Statement Per Line
Each statement in pseudocode should expressjust one action for the computer.  If the tasklist is properly drawn, then in most cases eachtask will correspond to one line ofpseudocode.
Task List
Read name, hours worked, rate ofpay
Perform calculations
gross = hours worked * rateof pay
Write name, hours worked, gross
Pseudocode
READ name, hoursWorked, payRate
gross = hoursWorked * payRate
WRITE name, hoursWorked, gross
Capitalize Initial KeywordCapitalize Initial Keyword
In the example below note the words: READ andWRITE.  These are just a few of the keywords touse, others include:
READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE
Pseudocode
READ name, hoursWorked,payRate
gross = hoursWorked * payRate
WRITE name, hoursWorked, gross
Indent to Show HierarchyIndent to Show Hierarchy
Sequence:
Keep statements in sequence all starting in the same column
Selection:
Indent statements that fall inside selection structure, but not the keywords that formthe selection
Loop:
Indent statements that fall inside the loop but not keywords that form the loop
Each design structure uses a particular indentation pattern
READ name, grossPay, taxes
IF taxes > 0
net = grossPay – taxes
ELSE
net = grossPay
ENDIF
WRITE name, net
End Multiline StructuresEnd Multiline Structures
See the IF/ELSE/ENDIF as constructed above,the ENDIF is in line with the IF.
The same applies for WHILE/ENDWHILEetc…
READ name, grossPay, taxes
IF taxes > 0
net = grossPay – taxes
ELSE
net = grossPay
ENDIF
WRITE name, net
Language IndependenceLanguage Independence
Resist the urge to write in whatever language youare most comfortable with, in the long run you willsave time.  Remember you are describing logicplan to develop program, you are notprogramming!
The Selection StructureThe Selection Structure
amount < 100
interestRate = .06
interestRate = .10
yes
no
IF amount < 100
interestRate = .06
ELSE
Interest Rate = .10
ENDIF
Pseudocode 
The Looping StructureThe Looping Structure
In flowcharting one of the more confusingthings is to separate selection from looping.This is because each structure use thediamond as their control symbol.  Inpseudocode we avoid this by using specifickeywords to designate looping
WHILE/ENDWHILE
REPEAT/UNTIL
WHILE ENDWHILEWHILE ENDWHILE
Start
count = 0
count
<10
add 1 to
count
write count
Write
“The End”
Stop
count = 0
WHILE count < 10
ADD 1 to count
WRITE count
ENDWHILE
WRITE “The End”
Mainline
count = 0
WHILE count < 10
DO Process
ENDWHILE
WRITE “The End”
Process
ADD 1 to count
WRITE count
 Modular
REPEAT UNTILREPEAT UNTIL
Start
count = 0
count
<10
add 1 to
count
write count
Write
“The End”
Stop
count = 0
REPEAT
ADD 1 to count
WRITE count
UNTIL count >= 10
WRITE “The End”
Mainline
count = 0
REPEAT
DO Process
UNTIL count >= 10
WRITE “The End”
Process
ADD 1 to count
WRITE count
 Modular
Advantages DisadvantagesAdvantages Disadvantages
Flowchart Advantages:
Standardized
Visual
Pseudocode Advantages
Easily modified
Implements structuredconcepts
Done easily on Word Processor
Flowchart Disadvantages:
Hard to modify
Structured design elements notimplemented
Special software required
Pseudocode Disadvantages:
Not visual
No accepted standard, varies fromcompany to company
Thank YouThank You