LoginSignup
13
10

More than 5 years have passed since last update.

多重ループから抜ける

Posted at

breakは、現在のblockを抜けるだけ。
多重ループを抜けるには、下記。

escape.rb
isBreak = false
10.times do |i|
  10.times do |j|
    if hoge()
      isBreak = true
      break
    end
  end
  break if isBreak
end
13
10
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
13
10