Problem with program - just learning Ruby

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!

You are mistaken string returned when Enter is hit without an input is
empty.
Enter generates a new-line sequence, so `gets’ does return “\n” on *nix
systems, “\r\n” on MS Windows etc.

There is a handy method `String#chomp’ for such situations which removes
separator from the end of a string. See the doc for a description.

Your input code should look like `words[x] = gets.chomp’ then.