I wrote this code myself, and it does work, but is there a better way to write this? For example, other ways of returning values so I can avoid the if and else statements. Or ways of making the code cleaner and not so messy looking. Also, it is advisable to use intergers 1 and 0 to represent true and false or is it better to just use the boolean values?
My code is:
int32 UBullCowCartridge::IsIsogram(FString Input) const{
int check = 0;
for (int o = 0;o < Input.Len()-1;++o) {
for (int i = o+1;i < Input.Len();++i) {
if (Input[o] == Input[i]) {
return check = 1;
}
} // End of for nested for loop
if (check == 1) {
return check;
}
} // End of outer for loop
if (check == 1) {
return check;
}
else
return check;
}
The code uses nested for loops to iterate through a word and check if there are more than one of any character in the word and once it finds a character that has been repeated, it will change the value of check and return it.
Then, the if and else statements are so the function knows what value it should be returning, as I am using 1 to represent true and 0 to represent false. Since I cannot return a value straight from the nested loops as that causes the error, “not all control paths return a value”.