lua-users home
lua-l archive

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


On Friday 14 June 2002 07:18, you wrote:
> > In older versions of Lua, the 'next' function may return the elements of
> > 't' out of order.
>
> That is not correct. Elements in a table has no order, so `next' cannot
> return them out of (or in) order.
>
> -- Roberto

So as a rule, don't count on 'next'.  Even though the elements appear to be 
ordered, one must remember that appearances can be deceiving!

Like so:

$ lua
Lua 5.0 (work0)  Copyright (C) 1994-2002 Tecgraf, PUC-Rio
> 
> x = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 }
> for n,v in x do print(n,v) end
1       1
2       2
3       3
4       4
5       5
6       6
7       7
8       8
9       9
10      10
11      11
12      12
13      13
14      14
15      15
16      16
17      17
18      18
19      19
20      20
21      21
> 

- Peter