a timer for a for loop

hello!
i’m programming an app that contains a data structure like this one:

for i=1,10,1 do 

  print(“i=”…i)

  for k=1,5,1 do

    print(“k=”…k)

    if k==5 then

    print (“secondary loop ended”)

  end

end

if i==10 then

print(“primary loop ended”)

end

now, what i want is that the program prints all the results with a delay time (for example, every second one of the results is printed)

is there any method, API or command able to do this???

thanks a lot

Hi,

Do you want a 1 second delay between each iteration, or only delay the display of the results (all the results) by 1 second?

Thanks

endy

hi,

i need a 1 sec delay between each iteration

thanks for your reply 

jepha

Use timer.performWithDelay()

As parameters you can pass a function to execute, the time interval in milliseconds, and the number of times to repeat the function (including infinitely).

fe:

local loopy = { i=1, k=1, timer = function(self,event) print("i k =",self.i,self.k) self.k=self.k+1 if (self.k\>5) then self.i,self.k = self.i+1,1 if (self.i\>10) then timer.cancel(event.source) end end end } timer.performWithDelay(1000,loopy,-1)

thanks davebollinger, perfect answer!!! and of course thanks also to everyone who wanted to help me

Hi,

Do you want a 1 second delay between each iteration, or only delay the display of the results (all the results) by 1 second?

Thanks

endy

hi,

i need a 1 sec delay between each iteration

thanks for your reply 

jepha

Use timer.performWithDelay()

As parameters you can pass a function to execute, the time interval in milliseconds, and the number of times to repeat the function (including infinitely).

fe:

local loopy = { i=1, k=1, timer = function(self,event) print("i k =",self.i,self.k) self.k=self.k+1 if (self.k\>5) then self.i,self.k = self.i+1,1 if (self.i\>10) then timer.cancel(event.source) end end end } timer.performWithDelay(1000,loopy,-1)

thanks davebollinger, perfect answer!!! and of course thanks also to everyone who wanted to help me