H
Helgitomas Gislason
Hello. When it comes to big, complex and long programs, you don't always
want to be needing to say at every single string:
if answer == 'exit'
exit
end
Get the point? Let's say you're making a program that's kinda like this:
--------------------
puts 'Hello, my name is Jimmy Hendrix. What\'s your name?'
puts ' '
name = gets.chomp
If name == 'Charlie' or name == 'Matt'
puts 'Ahh, great to see you. You're a boy.'
if name == 'Ann' or name == 'Sandria'
puts 'I see, you're a girl.'
end
----------------------
Now, if I wanted to exit my program lets say when I'm supposed to say
the name, I would be needing to do a, if name == 'exit', exit. and the
same thing if I wanted to exit when I was deeper in a longer program.
The main point I'm trying to get to here is: "Is there any function that
I can put at the beginning or the end, that says my program to exit
whenever I say exit WITHOUT having to put the:
if name == 'exit'
exit
end
at every string I want to have the possibility yo exit from??
want to be needing to say at every single string:
if answer == 'exit'
exit
end
Get the point? Let's say you're making a program that's kinda like this:
--------------------
puts 'Hello, my name is Jimmy Hendrix. What\'s your name?'
puts ' '
name = gets.chomp
If name == 'Charlie' or name == 'Matt'
puts 'Ahh, great to see you. You're a boy.'
if name == 'Ann' or name == 'Sandria'
puts 'I see, you're a girl.'
end
----------------------
Now, if I wanted to exit my program lets say when I'm supposed to say
the name, I would be needing to do a, if name == 'exit', exit. and the
same thing if I wanted to exit when I was deeper in a longer program.
The main point I'm trying to get to here is: "Is there any function that
I can put at the beginning or the end, that says my program to exit
whenever I say exit WITHOUT having to put the:
if name == 'exit'
exit
end
at every string I want to have the possibility yo exit from??