I’ve used a temporary variable (bool returnValue
) and a break in the loop.
Otherwise, the loop runs through even if only the first character is an uppercase.
Question : Would the temporary variable cost more in memory?
bool FBullCowGame::IsLowerCase(FString GuessWord) const
{
bool returnValue = true;
for (auto Character : GuessWord)
{
if (!islower(Character)) //if not a lower case letter
{
returnValue = false;
break; //Break the loop in case it has been found once, optimization.
}
}
return returnValue;
}