foreach to tell its location
Posted: Fri Jul 07, 2017 10:53 pm
I have many times encountered a situation where I have had to change "foreach" loop into "for n=1 to x" loop, because i have been in need of knowing the location.
as example:
this example is naturally not very good as you shouldnt remove stuff in middle of loop, but just to give you the idea.
For reasons like this, it would be handy to have something like "WhatIndexIsIt()" command which would tell at what index location it is currently going at.
as example:
Code: Select all
foreach(table, function(key, item)
if item = searchedthing then removeitem(table, ???)
endfunction)
For reasons like this, it would be handy to have something like "WhatIndexIsIt()" command which would tell at what index location it is currently going at.