Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Could someone tell me how FOR loops work in code? (These title requirements are crazy)

for i,v in pairs() do

I have looked around for tutorials on for loops and I checked the wiki but it I don't really understand how it works. If you could link me a video then that would be great!

2 answers

Most people use this type of loop to look inside of a table, i, will be the amount of items in the table and v will be the items it self example:

table = {apple, orange, peach}

for i, v in pairs (table) do

   print(i)-- will print 1, 2, 3
   print(v)-- will print apple , orange, peach

end

you can watch peaspod youtube video on this topic. I just started learning and thats a great place to start

2 comments

0

Please fix your code block.

0

Its just an example not really trying to run it on studio

For loops just really tells the script to meet a certain requirement to do something. They are split into three types of loops: For, while, and repeat. One being like you said~~~~~~~~~~~~~~~~~ for I,v in pairs() do

. The other can be 

local i = 1 while i < 10 do or local i = 1 repeat print(i,"< 10") i = i + 1 until i==10 print (i, "=10").


That is really all it is to it.

https://www.youtube.com/watch?v=ApggytDNfs8

That would be a good video to see.

This discussion is preserved as it was. New answers, comments, and votes are closed.