Having Trouble with the "for" loop

For some reason when I run my game it only checks the first letter against the second. Anything beyond that just removes a life. Anyone know why? Below is my “for” loop.

bool UBullCowCartridge::IsIsogram(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;
}

This C++ is kicking my butt, I was doing fine up until we started coding in Unity, instantly got lost and I’m trying to play catch-up. It feel almost nothing like what we were doing for the old C++ tutorials.

for (int32 Index = 0, Comparison = Index + 1; Comparison < Word.Len(); Comparison++);

You have a semicolon on the end of this line which means your code is actually

for (int32 Index = 0, Comparison = Index + 1; Comparison < Word.Len(); Comparison++);
{
    // Do nothing each loop
}
if (Word[Index] == Word[Comparison])
{
    return false;
}
return true;

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

Privacy & Terms