On 7/23/13 4:17 PM, John McKee wrote:
I'm confused.  I had a teacher, years ago, who was adamant - one way
in and one way out.  How is LEAVE considered structured?  Violates the
teacher's rule, since there are now multiple ways that a loop could be
exited.  His preferred method was to test at the top.
Many years ago, there was a level of fanaticism involving structured 
programming, combined with a very primitive understanding of it. It was 
exemplified in the inordinate popularity of Pascal, which had no concept 
of "LEAVE," and only grudgingly included a GOTO.
This primitive understanding assumed, in particular, that under normal 
conditions, an indexed loop always runs to completion, and should only 
exit early in case of an irrecoverable error. In fact, there's an 
obvious exception to this: table look-up. This led to numerous cases in 
which programmers were forced to choose between (1) storing the "found" 
value and continuing to waste processor resources iterating uselessly 
(perhaps at least skipping the "meat" of the loop), (2) substituting a 
DOWHILE or DOUNTIL construct, and handling the counter manually, or (3) 
using a GOTO.
It's rather telling that when Niklaus Wirth, the ultimate structured 
programming maven, designed a language for actual production use (Pascal 
was never intended as more than a teaching language), it *did* have a 
"LEAVE" (I don't remember, offhand, what it was called).
At any rate, where GOTO allows transfer of control to any labeled 
statement (in some languages, like traditional BASIC, all statements 
have labels), possibly even including transferring *into* a loop or 
inner-block in a way that bypasses any initialization, LEAVE simply 
exits the current iterative structure, going "out" the same way it would 
normally exit on completion, while ITERATE simply aborts the current 
iteration without actually exiting the loop.
--
JHHL
As an Amazon Associate we earn from qualifying purchases.