Author Topic: Foreach item oreder  (Read 1735 times)

zpaolo11x

  • Hero Member
  • *****
  • Posts: 1233
    • View Profile
    • My deviantart page
Foreach item oreder
« on: April 12, 2019, 04:57:24 AM »
I have this simple code:

Code: [Select]
local key_names = { "1": "A", "2": "B", "3": "C", "4": "D"}

foreach (key,val in key_names){
   print (key + " " + val +"\n")
}

Maybe I don't get it right but the console output of this code is

Code: [Select]
1 A
3 C
2 B
4 D

I would expect it to return

Code: [Select]
1 A
2 B
3 C
4 D

Also speaking of tables, what is the difference between something like this:

Code: [Select]
local aTable = { "first_key" : "Max Normal",
                 "second_key" : 42,
                 "third_key" : true};

and this:

Code: [Select]
local aTable = { "first_key" = "Max Normal",
                 "second_key" = 42,
                 "third_key" = true};