Home How can i continue the loop after getting value from function?
Reply: 1

How can i continue the loop after getting value from function?

Mohmmad
1#
Mohmmad Published in 2018-02-14 09:08:51Z

as i write in title, I have small question it's about loop! i've small loop, ok? i want pause loop in each value and call a function and wait a response from function, if function give any value i want to continue the loop! anyone have idea or suggest to help me at this? please don't give codes includes/or needs LUA Librares

Rok
2#
Rok Reply to 2018-02-14 10:14:32Z

Function calls inside loops will block by default in Lua (and any other language I can think of). So you do not have to worry about that. The loop won't continue as long the function doesn't return a value.

function is_done(x)
  if x == 5 then
    return true
  end
  return false
end

for i=1,10 do
  if is_done(i) then
    print('done!')
    break
  end
end

In the above example the loop breaks (stops) when i is equal to 5.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300588 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO