I'm doing a mini game in ruby I want to make that when the person answers yes, he flies to run the game
Ahem:
print "¿Desea volver a jugar si o no: "
respuesta = gets.chomp
How do I do it so that when I answer yes, the game is repeated?
I'm doing a mini game in ruby I want to make that when the person answers yes, he flies to run the game
Ahem:
print "¿Desea volver a jugar si o no: "
respuesta = gets.chomp
How do I do it so that when I answer yes, the game is repeated?
You can use any loop (or cycle) to achieve this, for example, using while
:
respuesta = "si"
while respuesta == "si" do
print "¿Desea volver a jugar si o no: "
respuesta = gets.chomp
end
This code generates a variable respuesta
with initial value "si"
to enter the cycle while
, once inside the question "¿Desea volver a jugar si o no: "
will be printed again and again until the user types the word "no"
.
It is important to note that with any other value that the user types (different from "si"
), the game will end (if you want it to be the other way around, that is, the game will continue unless you type "no"
, use until respuesta == "no"
).