LoginSignup
3
1

More than 5 years have passed since last update.

rubyで無限ループする(のとexitで脱出する)

Posted at

rubyで無限ループを実装したくて、perfect rubyにかかれていたloopというものを使ってみた。
ただ、そのまま使うと当然抜けれなくなるので、exitをいう文字列が入力されたらループを抜けるようにした。(getsメソッドの文字列そのままだと改行コードが付いてしまうので、chompするようにした。)

loop do
  input = gets.chomp
  puts input
  break if input == 'exit'
end
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1