Hi, I am learning Ruby from an online tutorial. I am trying to create a
program that lets you input as many words as you want until you hit a
blank enter. The program then sorts them in alphabetical order. I used
repl.it to type and run the program.
The first attempt looked like this:
words = []
x = 0
while words[x] = ''
words[x] = gets
x = x+1
end
puts words.sort
When I ran it, I put in three words and then hit a blank enter, but
instead of sorting the words, the program just moved the cursor to a new
line and accepted more input. Moreover, when I edited and ran the
program again, the computer would not exit out of the first program, so
I had to restart repl.it.
The edit looked like this:
words = []
x = 0
words[x] = gets
while words[x] != ''
x = x+1
words[x] = gets
end
puts words.sort
When I run this program, the program allows me to input one word, but
then puts the cursor on a new line and then freezes up.
What errors am I making in these programs?
Thanks for all your help!