while loop Lua code example

Example 1: continue in lua

-- Lua has no continue statement because it's designed to
-- be lightweight. Use goto instead:

arr = {1, 2, 3, 5, 6, 7, 8}

for key, val in ipairs(arr) do
  if val > 6 then
     goto skip_to_next
  end
  -- perform some calculation
  
  ::skip_to_next::
end

Example 2: lua while loops

--// Basic while true do loop

while true do
	
	--// Looped text
	print("Looped Text")
	
	--// Time the loop waits before looping again
	wait(1)
end

Example 3: while true do lua

while (statement) do
	-- code
end

Example 4: while loop bash

while true;
do
	#code
done

Example 5: while in lua

while(condition)
do
   statement(s)
end

Example 6: forever loop in lua

while( true )
do
   print("This loop will run forever.")
end

Tags:

Lua Example