Starting with version 1.23, the language has added support for iterators, which lets us range over pretty much anything!
Let’s look at the List type from the previous example again. In that example we had an AllElements method that returned a slice of all elements in the list. With iterators, we can do it better - as shown below.
Here is the code translated to Scilab:
Explanation:
We create a List structure and an element structure for linked list implementation.
The Push function allows us to add elements to the list.
The All function returns an iterator (inside Scilab’s function) that uses a nested function to yield values.
The genFib function demonstrates creating a Fibonacci sequence generator that uses iteration.
The main function demonstrates using these capabilities, iterating over list elements and generating Fibonacci numbers.
The output of running this script in Scilab would resemble: