---
title: "Comment by KOTP on \"Looping in Ruby\" | Hashnode"
description: "Nice writeup. I noticed that catch and throw was missing. def using_throw arr arr.each do |i| throw :early if i &gt; 5 puts arr[i] end end catch :early do using"
url: "https://hashnode.com/posts/looping-in-ruby/62564da76386ed96b050de2f/comment/62c98680e62bf98e0fb08386"
---

[Discussion](https://hashnode.com/posts/looping-in-ruby/62564da76386ed96b050de2f)

Comment [Looping in Ruby](https://hashnode.com/posts/looping-in-ruby/62564da76386ed96b050de2f)

[KOTP](https://hashnode.com/@KOTP)

[Jul 9, 2022](https://hashnode.com/posts/looping-in-ruby/62564da76386ed96b050de2f/comment/62c98680e62bf98e0fb08386)

Nice writeup.

I noticed that `catch` and `throw` was missing.

```
def using_throw arr

  arr.each do |i|
    throw :early if i > 5
    puts arr[i]
  end

end

catch :early do
  using_throw [1, 2, 3, 4, 5, 6, 7, 8]
end
```

Demonstrates that the catch does not need to be in the same method.

```
def using_throw arr

  catch :early do
    arr.each do |i|
      throw :early if i > 5
      puts arr[i]
    end
  end

end

using_throw [1, 2, 3, 4, 5, 6, 7, 8]
```

If we want to catch in the method itself.

[Kade Esterline](https://hashnode.com/@kadeesterline)

[Jul 11, 2022](https://hashnode.com/posts/looping-in-ruby/62564da76386ed96b050de2f/comment/62c98680e62bf98e0fb08386#reply-62cc583b0ba13ab923f68933)

Thanks for this!
