Help with Endless Loop


                local page = 2
		local multi = 0
		local lessthan = 13 * page
		local greaterthan = 13 * (page - 1)
		local backgroundPanel = vgui.Create( "DPanel", ShareFrame )
		backgroundPanel:SetSize( 600, 340 )
		backgroundPanel:SetPos(50, 65)
		backgroundPanel.Paint = function()
		draw.RoundedBoxEx(8, 0, 0, backgroundPanel:GetWide() + 50, backgroundPanel:GetTall() - 20, Color(255, 255, 255, 255))
			
			for k = (greaterthan + 1), lessthan, 1 do
				if tickets[k] then
					steamworks.RequestPlayerInfo( tickets[k].player )
					local var = 25 * multi
					surface.SetTextPos( 60, 3 + var )
					surface.DrawText( steamworks.GetPlayerName( tickets[k].player ) )
					surface.SetDrawColor( 0, 0, 0, 255 )
					multi = multi + 1
					if(multi == 13) then multi = 0 end
				end
			end	
                end

Does anyone have any idea why this would cause an endless loop? The tickets 15-26 do not exist in the table so I figured it would just load #14 and stop the loop, but it keeps going and results in the players name moving all over the GUI. Even after it reaches lessthan (26) it repeats itself. Does not happen if I have 26 ticket values (full page).

EDIT: Tried adding an else value to the if statement with the “break” function in it, still loops endlessly. If I put a print statement there it does register that the ticket does not exist.

a few tips:



if(multi == 13) then multi = 0 end


this can be changed to a modulo…



multi = (multi + 1) % 13;


Also, this is not a function with an instant callback.

Turns out that it was a problem with me using the variable multi, in multiple loops. I figured it would finish the loop, then set it to 0, then start the next loop but it looks like it ran at the same time causing multi to never equal zero.