Saturday, January 14, 2012

2.6. More on flowcharts. Box (Chapin) diagrams.

When have seen how to use flow charts to help us plan what a program should do. Translating from this tool to C# (or most other programming languages) is simple. But this kind of diagrams is old, and does not consider all possibilities of C# language (and many other current languages). For example, there is no simple way to represent a "switch" statement.

On the other side, a "while" loop would become a condition that makes a block repeat (an arrow which returns back to the point where the condition is checked):





And a "do .. while" loop becomes a condition at the end of a block that is repeated:



But there are other modern notations which can be more expressive. We'll discuss only one of them: Chapin diagrams (also called "box diagrams"). They represent each statement within a box:


Conditions are indicated by dividing the boxes into an upper part and two lower parts:


And the repetitive conditions are represented with a vertical bar on the left, which marks what is repeated. If the condition is checked at the end (do...while), we use this notation:


And this notation if the condition is at the beginning (while):


There is no special representation for the "for" statements.

No comments:

Post a Comment