-- Basic table sort -- Sample LUA code by www.astrofra.com print("Sort test #1"); -- table definition t = { 1, 4, 78, 12, 45, 65, 7845, 12, -45, -3, -8, -1, 0 }; i,j,n = 0,0,0; index_min = 0,0; -- how many items in table ? repeat n = n + 1; until (t[n] == 0); print("Table contains "..n.." elements : "); -- display table for i = 1,n,1 do print (t[i]..","); end; print ("\n"); -- sort table for i = 1,n,1 do -- for each item of the table index_min = i; for j = i+1,n,1 do -- for each item of the table, is it the smallest one ? if (t[j] < t[index_min]) then index_min = j; end; -- yes : then keep the position end; t[i], t[index_min] = t[index_min], t[i]; -- swap current item with the smallest one we found end print("Table sorted :"); -- redisplay table for i = 1,n,1 do print (t[i]..","); end; print("Done");