How can I change a value inside a loop every 10th iteration?
Say I have a list with 30 properties
JavaScript
x
12
12
1
myList = {"One", "Two", "Three", "Four" ..,"Thirty" } #trimmed
2
listLength = len(myList) #30
3
listRange = range(0, listLength) # 0-30
4
5
for i in listRange
6
7
x = ???
8
9
10
ops.mesh.add(size=2, location=(x)) # change value of x by 10 every 10 value
11
12
I would like to change the value of x by a factor of 10 every 10th time.
Desired outcome
JavaScript
1
4
1
first 10 values x = 10
2
second 10 values x = 20
3
third 10 values x = 30
4
**
Advertisement
Answer
Modulo is a nice way of doing that:
JavaScript
1
3
1
if i % 10 == 0:
2
x+=10
3
Edit: you should probably initialize x outside the loop.