Loop inside loop execute only every 4 iteration

Godot Version

4.6

Question

Currently just trying to figure out few concepts , and came cross now interesting thing which I haven’t face before, usually I use loops or while loops to meet certain amount, size, count but

when I have existing loop and inside I need to increase size of variables a,b,c,d only every 4 iterations what be best practice to do it ? Do I need external variable 4 , decrease inside loop by -1 , and then while variable be 1 execute logic and inside the this while reset value of variable back to 4 ?

	for i in numbers_of_steps:
		current_step_iteration += 1
		my_vertices.push_back(Vector3(start_vector.rotated(Vector3.UP, rotation_degree_value/float(current_step_iteration))))
		my_uvs.push_back(Vector2(0,0))
		my_normals.push_back(Vector3.UP)
		var a = 0
		var b = 1
		var c = 2
		var d = 3
		

here I’m trying to add this logic to get new values for indices .

Hi,

The best and most usual way of doing that is using the modulo operator, like this:
```
for i in numbers_of_steps:
if i % 4 == 0:
print(i) # This will print 0, 4, 8, 12, etc.
```

Modulo is a very fast operation, and that allows you not to declare another variable to keep track of the count.

1 Like

forgot that exist :slight_smile: thank you

1 Like