瀏覽代碼

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

Muller-Castro 11 月之前
父節點
當前提交
a36ff907f9
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      tutorials/scripting/gdscript/gdscript_basics.rst

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

@@ -1588,6 +1588,10 @@ in the loop variable.
     for x in [5, 7, 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}
     for i in dict:
         print(dict[i]) # Prints 0, then 1, then 2.