lua-users home
lua-l archive

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


is this the responsibility of the programmer or the
language ? step 0 means no step(stay there) and it
behave as it should, logically wise.

--- CHU Run-min <churunmin@gmail.com> wrote:

> for i = 10, 1, 0 do
> 
> end
> 
> This results in an endless loop. Why not check step
> for zero?
> 
>       case OP_FORPREP: {
>         const TValue *init = ra;
>         const TValue *plimit = ra+1;
>         const TValue *pstep = ra+2;
>         L->savedpc = pc;  /* next steps may throw
> errors */
>         if (!tonumber(init, ra))
>           luaG_runerror(L, LUA_QL("for") " initial
> value must be a number");
>         else if (!tonumber(plimit, ra+1))
>           luaG_runerror(L, LUA_QL("for") " limit
> must be a number");
>         else if (!tonumber(pstep, ra+2))
>           luaG_runerror(L, LUA_QL("for") " step must
> be a number");
>         setnvalue(ra, luai_numsub(nvalue(ra),
> nvalue(pstep)));
>         dojump(L, pc, GETARG_sBx(i));
>         continue;
>       }
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ