Carrying out the check without nested for loops

I know the challenge was to use nested for loops but I seem to have the same outcome (game works by adding just the one line, to increment Index on each loop so I ended up with:

    for (int32 Index = 0, Comparison = Index + 1; Comparison < Word.Len(); Comparison++)
    {
        if (Word[Index] == Word[Comparison])
        {
            return false;
        }

        Index++;
    }

Is there a reason not to do it that way? The nested loops seemed overly complicated for a relatively straight forward solution but maybe I’m missing something in my result that is bad practice.

1 Like

Won’t that return false only if the duplicate letters are right next to each other?

Yeah as Roach said,

This will increment Index before it is checked against the values after the next letter. for example in “cakes” It would only compare c->a, a->k, k->e and so on. I’m sure you figured this out, just replying now incase anyone else sees this

Privacy & Terms