Re: GSoft BASIC Ramble



limtc wrote:
Mmm... I think I disagreed with this statement, although I do see your
point.

Leave and exit statement are not simply "goto statement without a line
number". They are structure and proper ways of leaving a loop when a
condition occurred, and goto 1 place only. Leave statement will only
leave and land itself at the statement immediately after the loop and
nowhere else - they are actually implemented to discourage probably
the only uses of Goto.

One of the often occurred condition is this: loop through a list of
objects, and something occurred (eg collision detection), leave the
loop. In many cases, For is often a better loop than Repeat and While,
and having a "leave" statement allows this to be implemented easily.

If you look at the original ETH Pascal compiler sources, you will see
that "GOTO 1" (with "1:" at the end of a construct) is a very common
idiom.

As long as the idiom is used consistently, its meaning is very easily
understood by anyone reading the code.

It also has the advantage that any "standard" side effects can be
performed at the 1: label, prior to the procedure end--something that
a "RETURN" statement would not allow to be factored.

The problem with the GOTO statement is not its existence or its use,
but only its *undisciplined* use. Lots of words have been written
about why it should be banned from a language, as if that could prevent
undisciplined programming!

To those who need a counterexample, consider a state machine implemented
as a CASE statement inside a loop--any assignment to the switch variable
is, in fact, a GOTO to any case.

I mention this because I once tried to force "pure" structure on a
small system programming community--and the result was not pretty!

In my overzealous attempt to correct the ways of undisciplined
programmers, I also erected offensive obstacles to the efforts of
gifted, disciplined programmers.

One of my "favorites" was issuing a syntax error if any procedure went
across a page break! ;-) As you can imagine, a clear exception to
this rule was the lexical scanner, which contained a long but very
well structured CASE statement.

On 6ÔÂ8ÈÕ, ÏÂÎç10ʱ22·Ö, Mike Westerfield <Mike...@xxxxxxx> wrote:


Strangely enough, the reason there is no leave or exit statement in
Pascal is precisely because it is essentially a goto statement without
a line number. Anyone who criticizes goto because it is not structured
enough should not be using leave or exit, or break, continue and
return in C (except for the last line of a function). One of the
central tenants of structured programming was to have exactly one way
in or out of a loop or procedure.




--

-michael

AppleCrate: An Apple II "blade server"!
Home page: http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it's seriously underused."
.



Relevant Pages

  • Re: whats the prob with goto
    ... >> plz help me out of this dilemma, coz i use a lot of goto in my codes.... ... Programming paradigms like structured programming, functional programming, ... complexity, as program size increases so does complexity. ... A loop like: ...
    (comp.lang.c)
  • Re: Go To Portal Row script step 7.0-8.5
    ... The GOTO statement is not part of the ... FOR/NEXT loop syntax. ... ringleader of the bad programming gang. ... programming," it does not offer a GOTO command, and generally adheres to ...
    (comp.databases.filemaker)
  • Re: Go To Portal Row script step 7.0-8.5
    ... I should have included an extra step for incrementing X ... your program snippet results in an infinite loop: ... The GOTO statement is not part of the ... ringleader of the bad programming gang. ...
    (comp.databases.filemaker)
  • Re: page 124 of the camel book
    ... Then you don't need those remnants of goto. ... needing goto to get out of a deep loop. ... pushed when structured programming was hot. ... Search or Offer Perl Jobs ...
    (comp.lang.perl.misc)
  • Re: Iteration in lisp
    ... state machine is just a tagbody and goto. ... But if you need to change the state-transition-matrix in the middle ... loop and either table-driven or separate-functions for defining the ... (tagbody state1 (trace-state1 aux) ...
    (comp.lang.lisp)

Loading