Understanding "Checking Character Part 1"

Hi everyone. My problem is understanding “Checking Character Part 1” because I didn’t understand very well the declaration of two variables “Index” and “Comparison”.

bool UBullCowCartridge::IsIsogram(const FString Word) const
{
    // int32 Index = 0;
    // int32 Comparison = Index + 1;

    for (int32 Index = 0, Comparison = Index +1; Comparison < Word.Len(); Comparison++)
    {
        if (Word[Index] == Word[Comparison])
        {
            return false;
        }
    }
    
    return true;
    
    // For each letter.
    // Start at element [0].
    // Compare against the next letter.
    // Until We reach [Word.Len() -1]
    // if any are the same return false 
}

They’re just integers. Given Word is 5 letters long “plane” that loop would go

Index = 0, Comparison = 1
Index = 0, Comparison = 2
Index = 0, Comparison = 3
Index = 0, Comparison = 4

And

 if (Word[Index] == Word[Comparison])

Would go

Word[0] == Word[1] // p == l
Word[0] == Word[2] // p == a
Word[0] == Word[3] // p == n
Word[0] == Word[4] // p == e

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms