-4

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

Mohammed
  • 1
  • 1
  • 6
  • 1
    _i've small loop, ok?_ Okay... where is it? – B001ᛦ Feb 14 '18 at 09:10
  • i want an example, doing same idea – Mohammed Feb 14 '18 at 09:11
  • I didn't understand you, anyway i'll give you a small code but not working! code: `function DoSomething( value ) while ( value < 50 ) do value = value + 1 end if ( value >= 50 ) then return true end end Table = { 1, 3 , 5 } for _, v in pairs ( Table ) do bool = DoSomething( v ) if ( bool == true ) then print ( 'done' ) end end` – Mohammed Feb 14 '18 at 09:28

1 Answers1

1

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.

Rok
  • 787
  • 9
  • 17