lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I looked through the lua-l archives to find out the current status of the
"break" controversy.  Unfortunately, I couldn't figure it out.  It looked
as though almost everyone wanted some sort of break, but there was no
consensus about what kind to create.

I don't want to revive an old controversy, but Lua really needs a break
statement!  Break can do a lot of things, and admittedly not all of them
are good, but even an extremely simple break statement can be very useful.

For example, Soloway, et al. has shown that a while-loop with a single
exit statement somewhere inside is the easiest loop structure for students
to understand.  In C, that would be implemented like this:

while( 1 ) {
  [code before test]
  if( test ) break;
  [code after test]

Currently, the most obvious way to implement that in lua is this:

[ code before test ]
while test do
  [ code after test ]
  [ code before test ]

Which is obviously confusing and hard to maintain.  

Well, okay.  Maybe it's not obvious.  Here's a summary of Soloway, Bonar
and Ehrlich's Communications of the ACM article from vol 26 (1983), p 853.
They compare two languages, Pascal and "Pascal L" and see how novice,
intermediate and advanced programmers compare when writing a simple

"Pascal L", by the way, is something they made up.  It's pascal with Ada's
loop-with-exit added.  (Loop-with-exit is like the C example above.)
They also removed the other looping constructs.

They found that, if the problem can be expressed most naturally in a way
that the language supported directly, then novice, intermediate, and
advanced programmers could write programs correctly more significantly
more often.  

People may sneer at Ada a lot, but it's probably the most carefully
designed language out there.  Loop-with-exit is the prefered loop in Ada.
(Ada Quality and Style: Guidelines for Professional Programmers, Software
Productivity Consortium, 1989.)

Lua is a great language, but that doesn't mean that it wouldn't be a lot
better with some sort of break statement.  I really don't care about the
details of the break statement--I just want loop-with-exit to work.