My Code in the nested for loop Lecture 66

Hy Mike; I’ve a lot of your courses… congratulations.

Please, what’s your opinion about how I’ve done the for loop?
Notice that in the main for, I’ve coded Index < Word.Len() -1. I’ve done this code before see the solution, and I’ve done thinking in that is not necesary that Index arrives to Word.Len() because the variable Comparison will be always 1 greater than Index.
Thankyou for your response. It interests a lot to me, and sorry for my English.

Salvador

bool UBullCowCartridge::IsIsogram(FString Word) const
{
	/*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*/	

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

I came here to post the same thing. My code looks like yours.
I think the code in the tutorial performs one unnecessary loop in the upper one of the two nested loops.
It’s not much but it is something.

2 Likes

Privacy & Terms