Underlying structures are fairly standard, even though the particular “vocabulary” of pseudocode may vary.

One of the first things you may want to do, when you begin analyzing pseudocode someone else has written, is to identify the various structured-programming structures (constructs) that have been used. This is complicated somewhat by a lack of standards for pseudocode and the existence of many different programming “vocabularies.” It is common for a programmer’s vocabulary to be influenced by the target programming language or the programming language the programmer is most accustomed to using. The charts below list some of the more commonly encountered pseudocode forms along with the programming languages that influence each form and the standard structured-programming structure that the form implements.

So, for example, you might infer that the “Repeat … Loop until …” formused in the Learning Activities for Modules 4, 5, 6, and 8 are post-test “until” loops influenced by the Pascal programming language. On the other hand, you might conclude that the “Repeat while …” form used in the Learning Activities for Module 6 and the “Repeat until …” form used in the Learning Activities for Module 8 are not exactly like any of the listed programming languages, but probably represent a pre-test “while” loop and a pre-test “until” loop, respectively, similar to BASIC’s “DO WHILE …” and “DO UNTIL …”. Since there are no hard and fast standards for pseudocode, you may have to infer another programmer’s intentions while trying to find the standard structured-programming structure that best fits those intentions.

Here’s a (low tech) technique that can be very helpful. Get a print out of the pseudocode in question. Use pen or pencil (color is nice) to draw a box around each structured-programming structure. Remember that you can have structures nested inside of other structures. So, structures that contain other structures nested inside them may actually span several lines or more.In these cases, you will wind up with boxes inside boxes. If the programmer of the pseudocode has been careful to indent nested structures, that can also help you identify nested structure relationships.(Beware that the indention levels for the Learning Activities for Module 8 are not entirely consistent.) Using boxes in this way to clarify the structures and their relationships can help you when you come to recreate the same logic using flowcharts.

Miscellaneous Statement Forms
based on … / calculation, assignment / input / output / delimit statements in a compound statement / module call
Farrell / compute, add,
= (assignment) / get,
read / print, write / perform
COBOL / COMPUTE, ADD, SUBTRACT, etc., MOVE, SET / ACCEPT,
READ / DISPLAY,
WRITE / PERFORM,
CALL
BASIC / =(assignment operator) / INPUT, functions / PRINT,
WRITE
Pascal / :=(assignment operator) / procedures and functions / procedures / BEGIN … END
C/C++/Java / =(assignment operator) / functions and operators / functions and operators / { … }
SFC generic pseudocode
SFC flowchart / / / /
Farrell + Visio / / / /
Selection Structures
based on … / double and single selection / case construct
Farrell / ifconditionthen
body
else
body
endif / ifconditionthen
body
endif / case based onbasis
caseoption …
body …
default
body
endcase
COBOL / IFcondition
body
ELSE
body
END-IF / IFcondition
body
END-IF / EVALUATEbasis
WHENoption …
body …
WHEN OTHER
body
END-EVALUATE
BASIC / IFconditionTHEN
body
ELSEIFconditionTHEN
body …
ELSE
body
END IF / IFconditionTHEN
body
END IF / SELECT CASEbasis
CASEoption …
body …
CASE ELSE
body
END SELECT
Pascal / IFcondition
THEN
body
ELSE
body / IFcondition
THEN
body / CASEbasisOF
option:
body …
OTHERWISE
body
END
C/C++/Java / if(condition)
body
else
body / if (condition)
body / switch (basis)
caseoption: …
body
break; …
default:
body
SFC generic pseudocode / IF condition THEN
body
ELSE
body
END-IF / IF condition THEN
body
END-IF / SELECT basis
CASE option:
body
END-CASE
DEFAULT-CASE:
body
END-SELECT
SFC flowchart / / /
Farrell + Visio / / /

(Click here for a detailed chart of actual programming language syntax for case structures.)

General Loop Structures
based on … / pre-test loop (Do-While) / post-test loop (Do-Until)
Farrell / whilecondition
body
endwhile / do
body
untilcondition
COBOL / PERFORM UNTILcondition
body
END-PERFORM / PERFORM WITH TEST AFTER UNTILcondition
body
END-PERFORM
BASIC / DO WHILEcondition
body
LOOP / DO UNTILcondition
body
LOOP / DO
body
LOOP WHILEcondition / DO
body
LOOP UNTILcondition
Pascal / WHILEconditionDO
body / REPEAT
body
UNTILcondition
C/C++/Java / while (condition)
body / while (true)
{
if (condition)
break;
body;
} / do
body
while (condition) / while (true)
{
body;
if (condition)
break;
}
SFC generic pseudocode / WHILE condition DO
body
END-WHILE / LOOP
UNTIL condition
body
END-LOOP / REPEAT
body
WHILE condition / LOOP
body
UNTIL condition
END-LOOP
SFC flowchart / / / /
Farrell + Visio / / / /

(Click here for a detailed chart of actual programming language syntax for general loop structures.)

Pseudo-code and flowcharts may be written at various levels of refinement.

One of the techniques programmers and analysts use is that of “successive refinement.” When successive refinement is used, the process of understanding the problemand planning the logic may actually involve a number of smaller intermediate stages. For example, as you develop your procedural logic you may state a step such as
Calculate the average of three numbers.
This is a relatively “rough” level of refinement in that it doesn’t specify a great amount of procedural detail, but you would be perfectly justified in including it in the pseudocode or flowchart of your early analysis of the problem at hand. If your programming language already had a “calculate the average” function, it would be fairly straightforward to implement this step in actual source code.

On the other hand, if your programming language does not have such a function, or for other possible reasons, you may need or want to take the above statement through one or more levels of successive refinement (increasing levels of detail). You might ultimately end up with something like this:
Let counter = 0
Let total = 0
While counter < 3 do
Get a number
Add number to total
Add 1 to counter
Endwhile
Let average = total / counter
Print average
before you are ready to start actually coding the logic of your program. This level of refinement, as well, can be flowcharted as well as pseudo-coded.

The Learning Activities for Modules 4, 5, 6, and 8 contain mixed levels of refinement. For example, the form
Repeat

Loop until all numbers have been entered
is a fairly unrefined level, since it does not carry much detail as to how the computer will actually determine when all the numbers have been entered. Based on the fact that the procedural logic has previously asked the user how many numbers they want to enter, you could implement the loop as a counter-controlled loop. (But, oops, we don’t really discuss counter-controlled loops in depth until Module 6.) Another possible loop implementation would be to test for end-of-file, such as we have seen in Modules 1, 2 and 4. (But, then we wouldn’t need to ask the user ahead of the loop how many numbers they want to enter.) Of course, it is perfectly alright to flowchart at the same level of refinement as the given pseudocode. In that case, we would just use “all numbers have been entered” as the “until” condition of a post-test loop, thus finessing the issue for now. Granted that this condition does not meet all the formal requirements of a proper Boolean expression, but it is a “yes or no” question. So, it can stand, at least at this early level of successive refinement, as the decision criterion for any of the general loop forms, or the single or double selections, for that matter.

Visio or Structured Flow Chart (SFC)?

We have made two different flowcharting programs available to you. Which should you use? It is probably fair to say that Visio is the more powerful and commonly available of the two. However, each has certain advantages and disadvantages you may want to consider. I have listed some of those in the table below, along with a couple of tips for using each flowcharting program.

Visio / Structured Flow Chart (SFC)
powerful editing capabilities
full repertoire of standard flowcharting symbols and components
great flexibility of flowchart layout and connectivity
easier to diagramnew logic around existing logic / -rather limited editing capabilities
-somewhat idiosyncratic symbol forms
-hard to make major revisions in module’s logic without starting over
-twitchy dynamic connectors (arrowed lines)
-lack of built-in structure can allow a novice programmer to slip into spaghetti logic
-careful tweaking may be required to get a good looking and properly diagrammed flowchart / automatically positions symbols and lines according to a limited number of standard structured patterns
constrains programmer to develop properly diagrammed structured logic
automatically generates two forms of pseudocode in parallel with structured flowchart
•no constraints on how a flowchart is put together / •works best when programmeruses a top-down approach
•Be particularly careful of how your arrowed lines lay out. An arrowhead pointing in the wrong direction can be very misleading to the person reading your flowchart.
•Make sure all your lines lead from some kind of icon, and lead to some kind of icon or join with another line.
•Make sure all lines coming out of a decision are correctly labeled.
•Make sure each icon has a line coming in and one coming out—exceptions: terminals and decisions.
•Use methods similar to “Recognizing Structure” in Chapter 2 to check to make sure your flowchart is properly structured.
The “Farrell + Visio” diagrams in the above tables are actually embedded Visio objects. So, you should be able to copy and paste them into Visio for further editing. (Right click on a Visio diagram above. Choose Visio Object|Edit (or Open). Right click in the edit window and select Copy Drawing. You can then paste the drawing into an open Visio document.) / In SFC, the pre-test (“Test at Top Loop”) and post-test (“Test at Bottom Loop”) are both “while” loops. If you need an “until” loop, use the “User Controlled Exit Loop” option. That option provides loop body insertion points both before and after the exit condition. In fact, Pascal, BASIC, C, C++, and some versions of COBOL provide ways (besides “goto’s”)to conditionally exit from the middle of a loop body. SFC’s User Controlled Exit Loop allows for this, even though this departs from the strict tenants of structured programming. However, if you insert your loop body steps only after the exit condition or only before the exit condition, you will have a strictly structured pre-test “until” loop or post-test “until” loop, respectively.

ARR 6/30/2004