Looking for a way to create a slightly different kind of for loop behavior

Godot Version

4.1.3

Question

I’m still relatively new to gdscript. Is there a way to update the index in a for loop within the loop?

Example:
for i in 10:
print(i)
i = 0
print(i)
I was expecting this to loop forever, printing
0
0
over and over. Instead, it prints
0
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
and terminates. I think I understand the basics of why that happens, but I would like to be able to create the first behavior, without changing to a while loop.

In other languages,
for(int i = 0; i < 10; i++):
print(i)
i = 0
print(i)
something close to this would do what I was hoping for, as a reference.

Obviously my use case makes a bit more sense than just keeping it in an infinite loop though, this was just an easier example.

Sorry if this is formatted badly, I don’t know how to properly format posts here yet.

Edit: The indentation appears to disappear after I save this, for some reason. Hopefully it isn’t too bad.

No, it’s not possible, you’ll need to use a while loop.

Is it a limitation of the system, or just something that hasn’t been implemented? This is just curiosity now.

It’s an implementation detail, explained here GDScript reference — Godot Engine (stable) documentation in English

The loop variable is local to the for-loop and assigning to it will not change the value on the array. Objects passed by reference (such as nodes) can still be manipulated by calling methods on the loop variable.