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

5
1
Shakesbeer 105 points

                                    while(condition)
do
   statement(s)
end

5 (1 Votes)
0
4
3
SuperMDguy 105 points

                                    --[[
There are two types of lua for loops.
There is the generic definition, (pseudo-)expression, increment,
and there is one that allows the use of iterators.
]]

-- The first kind can be used like this:
for a = 0 --[[Define a as 0]], 10 --[[Continue until a reaches 10]], 2 --[[Increment by 2 each iteration]] do
	print(a); -- 0, 2, 4, 6, 8, 10.
end

-- The second kind requires an iterator. There are two commonly used built-in ones.
-- pairs and ipairs.

-- pairs uses the built-in next function, which gets the next key in a table given a previous key.
-- pairs can be used both for pure arrays and non-numerical indices (ie. maps).
for i,v in pairs({["A"] = 5, ["B"] = 10}) do
	print(i, v); -- A 5, B 10.
end

-- ipairs is different in that it can only loop over tables with numerical indices (ie. arrays) hence the name *i*pairs.
for i,v in ipairs({5, 10}) do
	print(i, v); -- 1 5, 2 10.
end

-- You can read more about iterators here:
-- https://www.lua.org/pil/7.3.html

4 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to define a while loop in lua how to make while loop in lua lua for in loop for in lua lua how to use while for lua script HOW TO make a for loop in lua how to make a do while loop in lua while and after lua lua number for loops how to do a loop in lua while loops in lua' lua fo loop while not lua do loop lua for loops lua while loop lus lua and in while loops for i in lua lua while looop bucle for lua lua for loop -1 how to make a loop in lua while do lua lua whilre loops lua for loop list how to while true loop in lua how to while not in lua how to loop a lua code for loop in lua while loop in lua loops in lua lua for loops lua loop lua for lua different ways to use a for loop lua loops lua for loo^ fort lua loop lua for loop ... lua for "..." how to do while loop in lua for lua while true in lua lua 5.3 for loop how to make a lua script loop lua for loop lua while do ho wto do for loop in lua do while lua == types of for loops lua while loop inside a function lua lue while loop for loop lua lua while loop but it execution lua for while for loop in lua example while in shell script lua for loop # roblox lua for loop lua while not do while lua lua how to stop minus breaking code while in lua how to have a function loop in lua at a interval how to how a function loop in lua for loop lua with variable how to loop in lua while x = 2 lua while var = 2 lua while var = lua while look lua lua increment by 1 loop lua WHILE LOOPS lua while and loop in lua while true do lua while else lua while statment lua lua while true while true loop lua do while loop lua while true lua while loop lua example lua while true loop lua while lua while true do lua do while while statement lua lua not while loop lua while statement example do while in lua while lua until not lua do while loop in lua lua loop while how to make a while loop in lua lua do while loop how to do a while loop in lua lua while statement while loop lua code lua while loop while true do loop lua while loops lua while loop lua lua while loops
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source