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

For i, v problem?

Asked by 9 years ago
for i, v = 0.1, -1 do
    -- Code goes here, but I can't figure out how to make it do like for example i, and v. Into one.
end 

I do that, and it errors.

0
Umm...try re-wording your question, this is kind of difficult to understand. dyler3 1510 — 9y

1 answer

Log in to vote
6
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

There are two types of for loops.

The numeric for loop goes over a range of numbers. It looks like this:

for count = start, stop do

The generic for loop uses an iterator to generate a bunch of values. It looks like this:

for a, b, c, d in expr do

If you're using a numeric for loop, there's only one variable.

for i = 0.1, -1 do

It will step by 1 however -- and -1 is smaller than 0.1 so your loop won't do anything at all. You need to specify how much you step by, the third thing:

for i = 0.1, -1, -0.1 do

This will use i as 0.1, 0, -0.1, -0.2, ..., -0.9, -1

Ad

Answer this question