Jump to content




test if for loop has ended


  • You cannot reply to this topic
2 replies to this topic

#1 Varscott11

  • Members
  • 23 posts

Posted 03 July 2016 - 10:14 PM

Basically, I want a line of code to be executed once a for loop has finally ended. My for loop is designed to search a table and satisfy an if statement:

local list={ [1] = "string1", [2] = "string2"}
local string
for key,value in pairs(list) do
if string == value then
--blah,blah,blah
end
end

--part that is supposed to execute code once the for loop is completed

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 July 2016 - 11:15 PM

What is the issue you're having? Your code is correct, logically, are you wanting to finish the loop once the if statement is satisfied?

You do have two issues:
- Your if statement will never fire because the 'string' variable has no value in it.
- You may experience issues because your variable is named 'string' which is an API within Lua, consider renaming it.

Edited by theoriginalbit, 03 July 2016 - 11:18 PM.


#3 Varscott11

  • Members
  • 23 posts

Posted 03 July 2016 - 11:18 PM

I ended up figuring out what I needed to do. I just needed to put the code I wanted to execute after the for loop's "end". Making that code execute, once the for loop is complete. I should have figured this out on my own. I guess it is late, and my brain is shutting down.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users