lua-users home
lua-l archive

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

On Tue, March 28, 2017 07:14, Ahmed Charles wrote:

>> I find this amusing because I've never written "len - 1" in a loop, I've
>> only ever written "!= len".


   You're amused?  I'm confused.  This list is about Lua.

   In Lua, the (numeric) 'for' loop takes explicit bounds,
   such as
             for i = 1, 10 do
   or, when iterating over a sequence,
             for i = 1, #t do
   (yes, there are cases where this is preferable to 'ipairs').

   This, to my mind, is distinctly better than having to write
             for i = 0, #t - 1 do

   Several other languages (Pascal, Modula-2/3, Fortran, ... )
   also have 'for' loops with explicit bounds.

   In Lua, and all of these languages, your '!= len' approach
   is simply not applicable.  Please correct me if I'm wrong,
   but 'len - 1' would be unavoidable if 0-based indexing were
   to be used in any such language.

   I'm very happy with Lua's approach.


Joseph Manning / Computer Science / UCC Cork Ireland /