4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Ruby]無限ループ方法まとめ

Posted at

はじめに

Rubyで無限ループを使う時に調べたらいくつかの方法が出てきたのでメモ。

無限ループ方法

無限ループとは、eachなどのメソッドのように、何回ループさせるか決めない時、処理を常に実行し続けたい時にしようします。
無限ループを止める場合はbreakreturnを使って終了させます。

###1. while
whiletrueの時にループします

while true do
  p “ループ”
end

###2. until
untilfalseの時にループします

until false do
  p “ループ”
end]

###3. loop

loop do
  p “ループ”
end

###4. step

1.step do |i|
  p “ループ”
end

おわりに

今回は無限ループの方法をまとめてみました。
他にも別のループ方法があるよ!という方はメッセージいただけると幸いです。

4
0
2

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
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?