With the provided input, the task is to translate the Go code example into GDScript. Here is how the code and explanation will look in Markdown format suitable for Hugo:
Starting with Godot version 3.2, GDScript has added support for iterators using the for loop, which lets us range over pretty much anything!
GDScript’s for loop ranges over iterators using the next() method to get the next element until has_next() returns false. We implemented the List class with a nested Element and Iterator class to handle iteration and the push method to add elements to the list.
The Fibonacci class generates an infinite sequence of Fibonacci numbers as long as the for loop continues. This is illustrated with a break statement when the current number equals or exceeds 10.
To run this code, attach it to a Node in your Godot scene and run the scene.
By leveraging GDScript’s support for iterators, we can elegantly iterate over custom data structures like lists or even infinite sequences like Fibonacci numbers. This makes GDScript both powerful and expressive for game development in Godot.