15
6

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 5 years have passed since last update.

Ruby で do ~ while xxx の条件文を使いたい

Posted at

Rubyには条件文を最後に持ってくる do ~ while xxx がないので、同等のこと使いたい

do ... end while はダメ

"ruby で do while をつかいたい"で検索してみると begin ~ end while xxxが紹介されてるんですがこれはMatzによって既にrejectされてるらしいです。

loop break if を使いましょう

.rb
loop do 
  # some code here
  break if <condition>
end 

な書き方が推奨らしいです。詳しく知りたい人は参照を見てください。

参照

15
6
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
15
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?