Giving a try to nested loops

I tried to take the loops to what’s going to come in the next lessons and went and tried to nest for loops to check each character against each other. It worked on my side with the following code in the IsIsogram() function:

bool UBullCowCartridge::IsIsogram(FString Word) const
{
    for (int32 j = 0; j < Word.Len(); j++) // 1st round check for each letter
    {
        for (int32 l = 0; l < Word.Len(); l++) // 2nd round check for each letter
        {
            if (Word[j] == Word[l] && j!=l) // comparing each letter against each other
            {                               // but excluding comparisons between same index numbers.
                return false;
            }
        }
        
    }
    return true;
}

don’t know if this approach would be problematic or functional.

thanks!

2 Likes

Great job with your nested loop!

Looks fine to me. The safety check is probably a good idea to have, since your goal is to return true for the function. Not sure if you need more checks, such as every second letter, or not. Besides if it works, that’s all there is to it, unless you’re looking for optimisation.

Thanks! after going further into the course I realized that the code we end up writing makes fewer checks so I’m guessing although in this version you write less code, this is more intense for processing especially if we were to check a great number of words? I guess what I’m wondering is what’s more optimized.

Privacy & Terms