Tables store data using hashed keys (slots) for indexing, to speed up processing. Otherwise they'd exponentially slow down with size.
So the objects get stored under a key hash, not the key itself. When iterating, again for sake of processing speed, the hashtable will be iterated. So they ARE in a specific order, it just is not obviously related to something meaningful for human eyes.
(PS: As Hashtable size and hence organization is also dynamic, iteration order could even change when adding slots)
And BTW, that's the main reason why slots/keys can only be integer or string, because that's what Squirrels' internal (quite fast) hash algorithm is limited to
If you need to order output, iterate through it and store the keys to an array, sort the array as you like, then iterate that array to output table keys/data like this:
Code:
local sorted=[] ;
foreach (slot,object in mytable) { sorted.append(slot) } ;
sorted.sort(@(a,b) a<=>b) ; //comparison works on strings, too... guess why and how ;-)
foreach (slot in sorted) { print (slot+" = " + mytable[slot]+"\n") ; }
}