lua-users home
lua-l archive

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



On 30-Aug-05, at 10:23 AM, Boyko Bantchev wrote:

Sorry, just couldn't resist the following :)

On 8/30/05, Rici Lake <lua@ricilake.net> wrote:
int i; for (i = 1; i <= 10; ++i) { ... }
for i = 1, 10 do ... end

Advantage: Lua, 16 fewer keystrokes

Not so.  Having once defined

#define DO(var,from,to) for (var=from; var<=to; ++var)

then

DO(i,1,10) {...}

That fails to declare i. Actually, I should have written the C line as follows:

{ int i; for (i = 1; i <= 10; ++i) { ... } }

You could actually write that as a macro in C9x, taking advantage of the bizarre syntax for declaring control variables inside for expressions. But afaik there is no way of doing that in C90.