I am working with Lua 5.1. This is the program I am currently trying to run.
print ("What is your name?")
playerName = io.read()
print ("Are you a boy or a girl?")
playerGender = io.read()
repeat
if playerGender ~= "boy" or "girl" or "male" or "female" then
print ("I'm sorry, that is not a valid answer.")
print ("Are you a boy or a girl?")
playerGender = io.read()
end
until (playerGender == "boy" or "girl" or "male" or "female")
No matter what, whether I enter one of the valid answers or if it's just random gibberish- the program responds with "I'm sorry, that is not a valid answer. Are you a boy or a girl?" Then you are prompted to enter your gender again- but no matter what the answer it just terminates the program- or it carries on to whatever other code there is to run.
Is there anything wrong with my code or logic that would be making the program to behave this way? Should I use something else other than the "repeat - if - then - end - else" block I am currently using? Any help would be appreciated!