Range Over Iterators in UnrealScript

UnrealScript doesn't have built-in support for iterators or generics like some modern programming languages. However, we can implement similar functionality using classes and arrays. Let's look at how we might implement a linked list and a Fibonacci sequence generator in UnrealScript.

First, let's define our `List` class:

```unrealscript
class List extends Object;

var Element Head;
var Element Tail;

struct Element
{
    var int Value;
    var Element Next;
};

function Push(int Value)
{
    local Element NewElement;

    NewElement.Value = Value;
    NewElement.Next = None;

    if (Tail == None)
    {
        Head = NewElement;
        Tail = NewElement;
    }
    else
    {
        Tail.Next = NewElement;
        Tail = NewElement;
    }
}

function array<int> All()
{
    local array<int> Result;
    local Element Current;

    Current = Head;
    while (Current != None)
    {
        Result[Result.Length] = Current.Value;
        Current = Current.Next;
    }

    return Result;
}

In this implementation, we use a struct Element to represent each node in the list. The Push function adds a new element to the end of the list, and the All function returns an array of all elements in the list.

Now, let’s implement a Fibonacci sequence generator:

class FibonacciGenerator extends Object;

function array<int> GenerateFibonacci(int Count)
{
    local array<int> Result;
    local int A, B, I, Temp;

    if (Count <= 0)
    {
        return Result;
    }

    A = 1;
    B = 1;

    for (I = 0; I < Count; I++)
    {
        Result[Result.Length] = A;
        Temp = A;
        A = B;
        B = Temp + B;
    }

    return Result;
}

This function generates a specified number of Fibonacci numbers and returns them as an array.

Now, let’s see how we might use these in a main function:

class MyGame extends GameInfo;

function PostBeginPlay()
{
    local List MyList;
    local array<int> AllElements;
    local array<int> FibNumbers;
    local int I;

    Super.PostBeginPlay();

    // Using the List
    MyList = new class'List';
    MyList.Push(10);
    MyList.Push(13);
    MyList.Push(23);

    AllElements = MyList.All();
    `Log("List elements:");
    for (I = 0; I < AllElements.Length; I++)
    {
        `Log(AllElements[I]);
    }

    // Using the FibonacciGenerator
    FibNumbers = new class'FibonacciGenerator'.static.GenerateFibonacci(6);
    `Log("First 6 Fibonacci numbers:");
    for (I = 0; I < FibNumbers.Length; I++)
    {
        `Log(FibNumbers[I]);
    }
}

In this example, we’re using the PostBeginPlay function as our entry point. We create a List, add some elements to it, and then print all the elements. We also generate the first 6 Fibonacci numbers and print them.

Note that UnrealScript doesn’t have a direct equivalent to iterators as seen in some modern languages. Instead, we’re using arrays to store and return multiple values. The for loops are used to iterate over these arrays.

Also, UnrealScript uses backticks (`) for its logging function instead of a print or console.log style function.

This code demonstrates how we can implement similar functionality to the original example, albeit with some differences due to the language constraints and conventions of UnrealScript.