I can't help but wonder if for loops can go backwards. Let me show an example with my code here.
part = script.Parent function sum(x, y, z) for i = 1, 10 do part.Position += Vector3.new(x, y, z) wait(0.01) end end while true do sum(1, 0, 0) sum(-1, 0, 0) end
I figured that if this for loop reaches its end/max value, it will stop and the while loop will call the next function and the for loop will go backwards by subtracting. Is this true? To be specific here, I thought for loops could only go forwards, because when I remove the second function call "sum(-1, 0, 0)", the for loop will keep going non-stop. I don't get it, I need to understand how this works. And sorry, I'm new to programming.
Hi, for loops have another feature that allows it to go backwards, your 3rd number states whether it goes forward or backward. By deafault, for loops think the 3rd number is 1 making it for 1 forward each time.
For example:
for i = 100,1,-1 do print(i) end
The third number makes it go 1 back each time, from 100 until it reaches 1
Hope this helped!
Any questions? Just ask!