mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
Update gdscript_basics.rst (#5873)
* Update gdscript_basics.rst Added some pragmatic advice for for-loops Co-authored-by: Max Hilbrunner <mhilbrunner@users.noreply.github.com>
This commit is contained in:
@@ -1143,6 +1143,24 @@ in the loop variable.
|
||||
for i in 2.2:
|
||||
statement # Similar to range(ceil(2.2)).
|
||||
|
||||
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 change
|
||||
the value on the array. Objects passed by reference (such as nodes) can still
|
||||
be manipulated by calling methods on the loop variable.
|
||||
|
||||
::
|
||||
for string in string_array:
|
||||
string = "Hello World" # This has no effect
|
||||
|
||||
for node in node_array:
|
||||
node.add_to_group("Cool_Group") # This has an effect
|
||||
match
|
||||
^^^^^
|
||||
|
||||
|
||||
Reference in New Issue
Block a user