A Night at the Movies loop


Hi, I have been trying to play with this code to make it so that when you finish adding a movie it will ask you what you want to do again and I can't seem to make it work. The best I can do is something like this:

movies = {
Memento: 3,
Primer: 4,
Ishtar: 1
def intro
puts "What would you like to do?"
puts "-- Type 'add' to add a movie."
puts "-- Type 'update' to update a movie."
puts "-- Type 'display' to display all movies."
puts "-- Type 'delete' to delete a movie."


choice = gets.chomp.downcase
case choice
when 'add'
puts "What movie do you want to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "What's the rating? (Type a number 0 to 4.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."

It doesn't allow me to have more user input. Thanks for the help


What's stopping you from putting all user-interaction code in a loop?


You mean putting the choice in the intro or making each choice (add, display etc) its own loop or making it just one long loop?


loop do
  all the things


Thanks! Didn't think about that. That was really helpful.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.