godot-docs
godot-docs copied to clipboard
Clarify use of "for" loops with arrays
Your Godot version: Godot Alpha 9
Issue description: Add the following beneath the documentation for the for loop
START:
If you want to assign values on an array as it is being iterated through, it is best to use for i in array.size()
.
for i in array.size():
array[i] = "Hello World"
The loop variable is local to the for-loop, and assigning to it will not influence the original value.
for string in array:
string = "Hello World" #this has no effect
END
URL to the documentation page (if already existing): https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html
Related: https://github.com/godotengine/godot/issues/61705
Someone merged this already. Documentation contains this and can be closed.
https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html
Closed by https://github.com/godotengine/godot-docs/pull/5873.