What is structured programming (was for/while else doesn't make sense)

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Thu Jun 16 01:57:02 EDT 2016


On Thursday, June 16, 2016 at 5:48:48 PM UTC+12, Rustom Mody wrote:
> On Thursday, June 16, 2016 at 8:25:10 AM UTC+5:30, Lawrence D’Oliveiro wrote:
> So here is the formal definition I remember from decades ago:
> 
> A structured flow-graph is one that has a single point of entry and exit.
> And is recursively made from smaller structured flow graphs
> With a finite set of 'graph combinators'
> 
> A structured program is one who's flow graph is structured
> 
> As I said I dont find this definition very useful since
> break is unstructured as is return, yield and much else.

On the contrary, it fits in nicely. Imagine trying to represent your code as a Nassi-Shneiderman diagram. This consists (recursively) of nested and/or concatenated sub-diagrams. Each piece has one entry point at the top, and one exit point at the bottom. In particular, it is *not possible* to express a goto that jumps from one arbitrary point to another--everything must strictly nest.

For example, a loop is entered at the top, and exited at the bottom. A “break” in the loop can cut it short, but it cannot violate this rule.

Even my C code follows this nesting principle, because it is goto-free.



More information about the Python-list mailing list