This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Varscott11's profile picture

test if for loop has ended

Started by Varscott11, 03 July 2016 - 09:14 PM
Varscott11 #1
Posted 03 July 2016 - 11: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
theoriginalbit #2
Posted 04 July 2016 - 12:15 AM
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 on 03 July 2016 - 10:18 PM
Varscott11 #3
Posted 04 July 2016 - 12:18 AM
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.