[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What's the rationale behind "for i=a,b[,c]"?
- From: Choonster TheMage <choonster.2010@...>
- Date: Tue, 17 Mar 2015 21:57:12 +1100
On 17 March 2015 at 21:45, Soni L. <fakedme@gmail.com> wrote:
>
> local a,b,c = 1,10,nil
> for i=a,b,c do print(i) end -- doesn't work because of the explicit nil :/
> why's nil not a valid "no value" here? :/
>
> So there's no easy way to do it, other than:
>
> local a,b,c = 1,10,nil
> if c == nil then
> for i=a,b do
> <mycode>
> end
> else
> for i=a,b,c do
> <mycode> -- we have to duplicate the code?!
> end
> end
>
> Which's bad due to duplicated code
>
>
> --
> Disclaimer: these emails are public and can be accessed from <TODO: get a
> non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.
>
>
What about this?
local a,b,c = 1,10,nil
for i = a, b, c or 1 do
<mycode>
end