This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
BlizzardAC's profile picture

If not input do nothing?

Started by BlizzardAC, 01 December 2015 - 11:50 PM
BlizzardAC #1
Posted 02 December 2015 - 12:50 AM
I'm pretty new to all this coding and such and one thing I'm good at is if / else commands. One thing I've been dying to know is that how I could make something like this work (just an example):

if input == "y" then
	  print("Hi")
	  sleep(2)
end
if input == "n" then
	  print("Bye")
	  sleep(2)
end
if input ~= "y" or if input ~= "n" then
--do nothing? how?nput = read()

Basically I want it to do something that if the input isn't y or n then it would let the user try again and input one of the options. How can I do this in the easiest way possible?
Lyqyd #2
Posted 02 December 2015 - 01:04 AM
The easiest way is by using the elseif and else keywords:


if input == "y" then
  --# yes
elseif input == "n" then
  --# no
else
  --# all other input
end
Dragon53535 #3
Posted 02 December 2015 - 01:56 AM
It seems like now is the time to show you loops!


local input
repeat
  input = read()
until input == "y" or input == "n"
if input == "y" then
  --#Do stuff
elseif input == "n" then
  --#Do stuff
end
BlizzardAC #4
Posted 02 December 2015 - 06:28 AM
It seems like now is the time to show you loops!


local input
repeat
  input = read()
until input == "y" or input == "n"
if input == "y" then
  --#Do stuff
elseif input == "n" then
  --#Do stuff
end
Wow! That's very easy. "until". Thank you very much! <3