godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Clarify use of "for" loops with arrays

Open NationalityNZ opened this issue 2 years ago • 1 comments

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

NationalityNZ avatar Jun 05 '22 17:06 NationalityNZ

Related: https://github.com/godotengine/godot/issues/61705

NationalityNZ avatar Jun 05 '22 17:06 NationalityNZ

Someone merged this already. Documentation contains this and can be closed.

https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html

Vennnot avatar Apr 25 '23 13:04 Vennnot

Closed by https://github.com/godotengine/godot-docs/pull/5873.

YuriSizov avatar Apr 26 '23 08:04 YuriSizov