|
Repeat is an oddball because it can get in trouble with continue. Continue is an oddball because it can get repeat into trouble. The problem is of course scope, in both arguments, because continue allows you to skip a piece of code without enclosing that code into a new scope (which is what happens with the regular "if...end" that some loathe inside a loop). While I agree with Roberto that we don't want to turn lua into C, the link provided by Rici does serve to inspire:
"An iteration statement is a block whose scope is a strict subset of the scope of its enclosing block. The loop body is also a block whose scope is a strict subset of the scope of the iteration statement."
Which is exactly what Chris indicated:
{ int i; for (i=0; i<10; i++) ... }
Wouldn't this solve our problems in lua as well? Neither repeat nor continue would cause any more problems, and a loop is just a loop with consistent scoping semantics. It would of course mean that you can't declare a variable local to the body of a loop and test its value in the loop condition (i.e. the repeat or while clause), which, it seems, is what many people want. Personally, I don't think this is right, but that's my 2 cents. You already couldn't do that with for and while loops, why should repeat be different?