Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Mapyo30 10
7 years ago
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

Log in to vote
-1
Answered by 7 years ago

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

0
Please fix your code block. GoldenPhysics 474 — 7y
0
Its just an example not really trying to run it on studio TheTopBoss -2 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago

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.

Answer this question