Post Reply 
Useful Programming Trick .. But 40 years late!
06-27-2016, 11:33 AM
Post: #12
RE: Useful Programming Trick .. But 40 years late!
(01-21-2016 08:59 AM)ttw Wrote:  Just to mess with Structured Programming (as opposed to structured programming):

While (I>0)
End While

This skeleton will perform arbitrary sets of forward and backward jumps in a Structured Manner.

This solution is often used to translate programs from languages which have GOTO statements (e.g. early BASIC) to languages which do not have them (like Java).

The program is translated into a large switch structure as shown, with "case" statements for each a GOTO target and "break" statements for each GOTO. Just before the "break" the switch variable is set to the label (e.g. line number) of the GOTO target.
The while loop simulates the process of running through the original program lines. It is possibly but not necessary to have case statements for each line, they are needed only where jumps occur. Thus you can make any ugly old spaghetti BASIC or FORTRAN program into a "well structured" Pascal program ;-)

"Look Ma: no GOTO!"

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Useful Programming Trick .. But 40 years late! - Martin Hepperle - 06-27-2016 11:33 AM

User(s) browsing this thread: 1 Guest(s)