while str = gets.chomp break if str == "q" || str == "退出" puts "输入的内容:#{str}" end 简单的使用while完成输入内容打印并输入指定命令后退出循环!