lua-users home
lua-l archive

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


2012/11/20 David Favro <lua@meta-dynamic.com>:


> local rv1;
> repeat
>     local rv2;
>     rv1, rv2 = foo();
>     until rv2;
> -- use rv1 here...


> Is there some other idiom to accomplish this in the current language
> with a nicer look than my first snippet?

If the only purpose of rv2 is to drive the loop, then:

Inside foo(): instead of

   return rv1, rv2

put

  if ~rv2 then return rv1 end

Then the calling code becomes:

local rv1
for v in foo() do
   rv1=v
end

I