Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Structured program theorem
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Single-while-loop, folk version of the theorem === This version of the theorem replaces all the original program's control flow with a single global <code>while</code> loop that simulates a [[program counter]] going over all possible labels (flowchart boxes) in the original non-structured program. Harel traced the origin of this folk theorem to two papers marking the beginning of computing. One is the 1946 description of the [[von Neumann architecture]], which explains how a [[program counter]] operates in terms of a while loop. Harel notes that the single loop used by the folk version of the structured programming theorem basically just provides [[operational semantics]] for the execution of a flowchart on a von Neumann computer.<ref name="Harel"/>{{rp|383}} Another, even older source that Harel traced the folk version of the theorem is [[Stephen Kleene]]'s [[Kleene's T predicate|normal form theorem]] from 1936.<ref name="Harel"/>{{rp|383}} [[Donald Knuth]] criticized this form of the proof, which results in [[pseudocode]] like the one below, by pointing out that the structure of the original program is completely lost in this transformation.<ref>{{cite journal | author = Donald Knuth | title = Structured Programming with go to Statements | journal = Computing Surveys | volume = 6 | issue = 4 | year = 1974 | pages = 261β301 | doi = 10.1145/356635.356640 | citeseerx = 10.1.1.103.6084 | s2cid = 207630080 }}</ref>{{rp|274}} Similarly, Bruce Ian Mills wrote about this approach that "The spirit of block structure is a style, not a language. By simulating a Von Neumann machine, we can produce the behavior of any spaghetti code within the confines of a block-structured language. This does not prevent it from being spaghetti."<ref name="Mills2005">{{cite book|author=Bruce Ian Mills|title=Theoretical Introduction to Programming|year=2005|publisher=Springer|isbn=978-1-84628-263-8|page=279}}</ref> <syntaxhighlight lang="pascal"> p := 1 while p > 0 do if p = 1 then perform step 1 from the flowchart p := resulting successor step number of step 1 from the flowchart (0 if no successor) end if if p = 2 then perform step 2 from the flowchart p := resulting successor step number of step 2 from the flowchart (0 if no successor) end if ... if p = n then perform step n from the flowchart p := resulting successor step number of step n from the flowchart (0 if no successor) end if end while </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)