lua-users home
lua-l archive

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


On Tuesday 04 October 2005 18:33, Javier Guerra wrote:
[...]
> i think you got 'continue' wrong.  i'd expect it to goto the loop test, not
> after it.

In C, continue does indeed jump to the end of the loop, just before the test. 
(I just checked it.)

This means that the following:

int i = 0;
do
{
	i = i + 1;
	printf("%d\n", i);
	if (i < 10)
		continue;
}
while (0)

...prints '1' and terminates, rather than (as I was actually expecting) 
1...10. (I don't use do...while myself.) In the case of 'while(){}', jumping 
to the end of the loop is equivalent to jumping to the beginning of the loop.

[...]
> now it's semantically right, but still wouldn't compile because of the
> "local g, rest"!  the only fix is to write:
[...]
> which is just uselessly ugly

Indeed. I run into this frequently with C++ when using goto, and...

> maybe if we could think of 'continue' as syntactic sugar for a if...end
> block, any local defined after it would be in a smaller scope, that doesn't
> include the test condition.

...my usual solution is to start a new scope immediately after the goto that 
lasts until the end of the block. Exactly what you were describing, in fact.

[...]
> <warning> i haven't ever worked the insides of any compiler, not even read
> the Lua sources; anything i say here might save us, or destroy Lua as we
> know it </warning>

It's amazing how complicated a simple jump instruction can be...

-- 
+- David Given --McQ-+ "Working with Unix is like wrestling a worthy
|  dg@cowlark.com    | opponent. Working with Windows is like attacking a
| (dg@tao-group.com) | small whining child who is carrying a .38." ---
+- www.cowlark.com --+ Nancy Lebovitz

Attachment: pgpB7IAhrBUzz.pgp
Description: PGP signature