ID:1511268
 
(See the best response by Nadrew.)
Hey guys,

I'm looking for alternative, faster and perhaps more efficient methods for looping through a list. Using a for loop seems like the more default method, but I'm sure there must be ways that are somewhat faster than that.


Thanks in advance, guys, have a nice day :P
Best response
for() is pretty much the best way, and the for(key in list) notion is actually the fastest way that exists in the language.

You could use for()'s other syntax like:

for(var/i = 1, i <= mylist.len, i++)
world << mylist[i]


But it's not any faster, if anything it's slower because it does an index-lookup the way it does.
or, the the for-to-step format:

for(var/i = 1 to list.len) world << list[i]


with step, you can iterate over every other thing in the list, every 3, etc.
for(var/i = 1 to list.len step 2) world << list[i]


tho, the default x in container way is probs the best.