Looping over expect script not working : New at scripting, beware...

I'm attempting to use this code that i put together from reading a couple blogs. The idea is for this script to read the IPs that i have saved on ips.txt and then run the code to ssh to the read IP using the credentials given, perform a couple send commands as described below, exit the ssh session, and repeat with the second line in the ips.txt file, which is a different IP, until it finishes the IPs list. 

Note: the ips.txt file is a simple list of IP addresses as follows (no spaces between the IPs):

192.168.0.2

192.168.0.3

192.168.0.4

...

The spawn, expect, and send commands work fine. It also loops fine back up to the beginning of the code but it will NOT read the second IP in the ips.txt file; it will just read the first one again and perform the same steps over and over. 

Please assist...
#!/usr/bin/expect

set timeout 180
set username admin
set password Changeme1
set fildes [open "ips.txt" r]
set ip [gets $fildes]

while {[string length $ip] != 1} {
   spawn ssh $username@$ip
   expect "password:"
   send "$password\r"
   expect ".mi"
   send "show sw\r"
   expect ".mi"
   send "exit\r"
   set ip [gets $fildes]
   }

close $fildes
