This works:
#Loop naming accounts====================
num = 0 #<--Generic counting variable
loop do
print ("\nEnter account name or press 'q': > ")
names[num] = gets.chomp
if names[num] == "q"
break
end
puts ("The account name is #{names[num]}.")
num += 1
end
The obvious problem here is that I don't want "q" to be one of the accounts.
This doesn't work:
#Loop naming accounts====================
num = 0 #<--Generic counting variable
loop do
print ("\nWould you like to add an account? [1 - yes] [2 - no]: > ")
varr = nil
varr = gets.chomp.to_i
if varr == 2
break
end
names[num] = gets.chomp
puts ("The account name is #{names[num]}.")
num += 1
end
This sends my terminal to a completely black screen. Questions:
Why does the first example work for breaking out of the loop, but the second one will not?
Why is the second example weirdly breaking to a completely blank screen rather than throwing an error, etc?
How do I properly do this?
Thanks!