Posted 20 September 2016 - 05:46 AM
So I'm trying to be able to handle different ways a user could type things in my code, and I'm stuck.
What I'm trying to do, right now, is if the user types "Bye", "Goodbye", "bye", or "goodbye", the loop will exit, otherwise it will continue to run.
I know I could do this with an if then with some and's, but I'm trying to work with a while statement.
So, what I (thought) I could do is just compare the user's input (from read()) to a table containing each variation of "bye".
Aaaand I'm not entirely sure how to do that.
This code works correctly, but only if the user types exactly "bye", as it's only comparing it to the first string inside the function "bye"
How would I go about comparing a string to all the variables inside a table, with a while function?
Is that even possible?
I looked at the built-in "go" program for turtles, since it has a similar ability, but it seems to be laid out a bit differently, and I wasn't sure how it's actually using the information.
What I'm trying to do, right now, is if the user types "Bye", "Goodbye", "bye", or "goodbye", the loop will exit, otherwise it will continue to run.
I know I could do this with an if then with some and's, but I'm trying to work with a while statement.
So, what I (thought) I could do is just compare the user's input (from read()) to a table containing each variation of "bye".
Aaaand I'm not entirely sure how to do that.
This code works correctly, but only if the user types exactly "bye", as it's only comparing it to the first string inside the function "bye"
local input=tostring(read())
local byeVars={"bye","goodbye","Bye","Goodbye"}
while input~=tostring(byeVars[1]) do
input=tostring(read())
end
print("Goodbye!")
How would I go about comparing a string to all the variables inside a table, with a while function?
Is that even possible?
I looked at the built-in "go" program for turtles, since it has a similar ability, but it seems to be laid out a bit differently, and I wasn't sure how it's actually using the information.