Prechádzať zdrojové kódy

Add typed loop variable example in GDScript reference (#9388)

Muller-Castro 11 mesiacov pred
rodič
commit
a36ff907f9

+ 4 - 0
tutorials/scripting/gdscript/gdscript_basics.rst

@@ -1588,6 +1588,10 @@ in the loop variable.
     for x in [5, 7, 11]:
     for x in [5, 7, 11]:
         statement # Loop iterates 3 times with 'x' as 5, then 7 and finally 11.
         statement # Loop iterates 3 times with 'x' as 5, then 7 and finally 11.
 
 
+    var names = ["John", "Marta", "Samantha", "Jimmy"]
+    for name: String in names: # Typed loop variable.
+        print(name) # Prints name's content.
+
     var dict = {"a": 0, "b": 1, "c": 2}
     var dict = {"a": 0, "b": 1, "c": 2}
     for i in dict:
     for i in dict:
         print(dict[i]) # Prints 0, then 1, then 2.
         print(dict[i]) # Prints 0, then 1, then 2.