how do i use 'for i=1 to 10' loop?
I know how it works i just want to know how to use it a little better
I know how it works i just want to know how to use it a little better
so basically i starts at zero and the 1 is how much it skip counts by so if it were 2 then it would go 2,4,6,8,10 until it hits 10 the ten is the time it repeats so you could replace it with a variable
also i becomes a variable which i's value can be called other places in the program so like print(i)
ty
yw
This is not how it works at all.
With for i=1 to 10
it'll create a variable i
for you with a starting value of 1. You can use this variable while inside the for loop, like this:
for i=1 to 10
print(i)
end
i
will be increased by 1 on each iteration of the loop, until it reaches 10.
The example will write 1 2 3 4 5 6 7 8 9 10
.
Changing the number will change the range. For example, you can start from 2 this way:
for i=2 to 10
print(i)
end
This will produce 2 3 4 5 6 7 8 9 10
.
You can even start with the higher number and make it to count downwards.
for i=5 to 2
print(i)
end
This will give you 5 4 3 2
.
In all those examples, i
always changes by 1. To change the step, you need to use an additional by
element.
for i=2 to 10 by 2
print(i)
end
A loop like this will give you 2 4 6 8 10
.
And last thing, you can name the variable something different, too.
for my_counter=1 to 100 by 42
print(my_counter)
end
wdym im completely wrong i may have not had all of it but i explained most of the things you said
well thanks to both of you