Fence Diagrams- "Flow Charts" but Created and Editable by Programmer's Editor
- davidcarew19

- 3 days ago
- 3 min read
There are three fundamental logical controls within computer programs:
Sequencing logical steps: do this step then do next step, etc. wherein the order of the steps must be done as specified.
Alternation of steps (IF / THEN / ELSE), wherein a bloc of steps will execute if and only if some controlling tested logical condition is true. Sometimes a programming language allows for an ELSE clause whereby an group of steps will execute only if the controlling logical condition is NOT true. Often this is shown in computer code by IF <condition> THEN <bloc of steps done when logical condition is true> ELSE <bloc of steps executed when the logical condition is false>
Iteration of logical steps (Repeating a sequence of steps also known as looping). There are two sorts of iteration (as used by this Fence Diagramming notation)
DO-WHILE controls a repetition of a group of computer steps while some controlling logical condition(s) remain(s) true
DO-WHILE iterates zero or more times-- if the logical control condition(s) is/are not true initially, then the steps in the iteration do not execute at all.
DO-UNTIL repeats (iterates) a block of steps until the controlling logical condition(s) become(s) true.
DO-UNTIL iterates one or more times-- the controlling logical condition(s) is/are tested at the "bottom" of the loop, that is after the steps of the iteration execute at least once. Another iteration of steps occurs when the logical controlling conditions are false
Flow charts are not commonly required as part of the design and preparation for writing computer programs. HOWEVER, there is still some reason to have a "charting" technique that makes program logic explicit before the logic is codified into a formal program. Fence diagrams are completely equivalent to traditional flow charting, with the advantage that programmers can create and edit them using their most commonly used, daily tool-- the programmer's text editor.
This web log post presents fence diagram outlines illustrating each of these fundamental control structures:
1 2 3 4 5 6 7
12345678901234567890123456789012345678901234567890123456789012345678901234
[SEQUENCE]
Step n Step n+1 Step n+2 [...]
============= ============= ============= =============
| | | |
|=============>| | |
| |============>| |
| | |==============>|
| | | |=======>[...]These diagrams use mono-spaced font type so that you can cut and paste templates to
use in charting parts of your code.
1 2 3 4 5 6 7
12345678901234567890123456789012345678901234567890123456789012345678901234
[ALTERNATION IF-THEN]
IF <protected: > <after ENDIF>
<conditions> <do if true > <next step > [...]
============= ===={bloc}==== ============= ===========
|====[true]===>| | |
| : | | |
| <OR> | | |
| : | | |
|====[false]================>| |
| | |=============>|IF-THEN-ELSE has two indivisible blocs
[ALTERNATION- IF-THEN-ELSE]
IF THEN ELSE <after ENDIF>
<conditions> <do if true > <do if false> <next step >
============= ===={bloc}=== ===={bloc}==== =============
| | | |
|====[true]===>| | |
| : |=============================>|
| <OR> | | |
| : | | |
|====[false]==================>| |
| | |=============>|
| | | |======>Last are the two types of iteration (loops):
[ITERATION - UNTIL-DO]
<iteration >
UNTIL: DO: <body steps > <conditions > <step after >
<conditions> <first step> [...] <test: T/F > <iteration >
============= ============= ===={bloc}==== ============= =============
| | | | |
|=============>| | | |
| |=============>| | |
| | |==============>| |
|<===============================<[false]<====| |
| | | |===>[true]>==>|
| | | | |=====>And the WHILE - DO iteration:
[ITERATION - DO-WHILE]
ITERATION
DO WHILE <iteration > <iteration > <step after >
<conditions> < 1ST step > <body steps> <iteration >
============= ============= ====[bloc]=== =============
| | | |
| [conditions] | | |
|=[false-end ]===============================>|
| [iteration ] | | |
| : | | |
| <OR> | | |
| : | | |
|=[iterate]===>| | |
| |=============>| |
| | | |
|<====[top:test conditions]===| |=======>Now that I have learned to enter monospaced type in the guise of "code snippets", it is perhaps time to re-write some entries that are mostly code...

Comments