I don’t see how this would not raise a warning. You still have the return statement inside the loop. Also, you shouldn’t be setting the Status like that, that’s the job of BCGame.CheckGuessValidity
. The break
in here isn’t doing anything since the program would reach the return statement and exit the function, you can see this by adding a breakpoint there and stepping through the code one line at a time.
What the computer sees is that there is a loop and inside that loop there is a switch statement. Only one of the cases (the default) has a return, the other’s don’t and if the while condition isn’t true, it would have reached the end of the function without ever calling a return. We as humans know that that scenario is not possible but the compiler doesn’t.
I find Ben’s logic much simpler to follow for any average programmer:
FText Guess = "";
Status = Invalid staus;
do
Guess = user input
Status = BCGame.CheckGuessValidity
if the Guess is wrong, tell the player why and loop again.
if the Guess is OK, exit the loop (the Guess is valid)
return the valid Guess
In the end, it doesn’t matter what happens inside the loop since the last line of the function is a return Guess;
so as far as the compiler is concerned, it will always return something.