Hello,
I am new to programming in general, and I was having a difficult time
figuring out the solution to this problem as well as thinking of good
key words that would help me find the solution online.
My problem is simply that I do not know what the value of a 'gets' that
doesn't contain anything is. I want this program to end if someone just
hits enter for the gets response, and I don't know how to represent that
in the program itself.
puts 'Enter as many words as you please, one per line. Press enter to
quit.'
array = []
input = gets.chomp.downcase
if input != # Not sure what should go here
while input != # Not sure what should go here
array.push input.capitalize
input = gets.chomp.downcase
end
else
end
puts array.sort
If anyone could help me out with this I would be very grateful. I am
sure there is a very simple solution, but I have been looking around
quite a bit, and have been unable to find anything.
On Sat, Jun 6, 2009 at 7:50 PM, Matt Garriott<matt.garriott@gmail.com> wrote:
Hello,
I am new to programming in general, and I was having a difficult time
figuring out the solution to this problem as well as thinking of good
key words that would help me find the solution online.
My problem is simply that I do not know what the value of a 'gets' that
doesn't contain anything is. I want this program to end if someone just
hits enter for the gets response, and I don't know how to represent that
in the program itself.
puts 'Enter as many words as you please, one per line. Press enter to
quit.'
array =
input = gets.chomp.downcase
if input != # Not sure what should go here
while input != # Not sure what should go here
array.push input.capitalize
input = gets.chomp.downcase
end
else
end
puts array.sort
If anyone could help me out with this I would be very grateful. I am
sure there is a very simple solution, but I have been looking around
quite a bit, and have been unable to find anything.
Hello,
I am new to programming in general, and I was having a difficult time
figuring out the solution to this problem as well as thinking of good
key words that would help me find the solution online.
My problem is simply that I do not know what the value of a 'gets' that
doesn't contain anything is. I want this program to end if someone just
hits enter for the gets response, and I don't know how to represent that
in the program itself.
And then the chomp function which he calls on the string removes the \n
from the end, making it an empty string.
···
On Mon, 08 Jun 2009 14:59:31 +0900, 7stud -- wrote:
7stud -- wrote:
print "Enter: "
input = gets
p input
--output:--
Enter:
"\n"
Whenever you hit Enter/Return on your keyboard, you are adding a
"newline" to the input. A newline is signified by the string "\n".
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/