For next loop (SOLVED)

for a = 1,#datasch do
            dums=string.sub(datasch[a]["Name"],1,4)
            if dums=="Pass" or dums=="Bulk" then
                    lv.selectedItem=a
                    tw=datasch[lv.selectedItem]["To"]
                    sw=shex.." "..sname
                    if tw==sw then
                        anote=false
                        SellCargo:check(lv.selectedItem)
                        SellCargo:sell()
                        a=1
                    end
            end
        end

The above is an example from my code and I am having trouble resetting the loop to the start. Is there a way I can do this. Basically I want it to check through and when it finds the match it starts at the beginning until no matches found.

Thanks in advance for any help in this matter.

Turn it in to a function, then when it finds it use break to break the current loop and call the function from within the loop restart it, make sure this isn’t infinite (the recursive calls).

Try a while loop with an iterator?

A while loop is what you’re looking for.

a = 1
while a <= #datasch do
            dums=string.sub(datasch[a]["Name"],1,4)
            if dums=="Pass" or dums=="Bulk" then
                    lv.selectedItem=a
                    tw=datasch[lv.selectedItem]["To"]
                    sw=shex.." "..sname
                    if tw==sw then
                        anote=false
                        SellCargo:check(lv.selectedItem)
                        SellCargo:sell()
                        a=0
                    end
            end
            a = a + 1
        end

Would like to say thanks for all the help and @SkyTheCoder the code worked.

I changed the title from CLOSED to SOLVED. “Closed” threads are usually ones that are formally closed because we actively don’t want any more posts on (usually because the discussion has veered in to topics that aren’t healthy for the community). “Solved” threads are those where there was a problem that has now found a solution, so there’s no need for further eyes on it but it might still be of interest to others with similar problems.