---
title: "Discussion on \"Looping in Ruby\" | Hashnode"
description: "Discussion on \"Looping in Ruby\". Looping in Ruby\nAn important and powerful concept to understand in any programming language is looping. By using loops we can iterate through arrays and interact with each piece of data in the array until a certain condition is met. If you know how t..."
url: "https://hashnode.com/posts/looping-in-ruby/62564da76386ed96b050de2f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Looping in Ruby](https://kadeesterline.hashnode.dev/looping-in-ruby?utm_source=hashnode&utm_medium=feed)

Looping in Ruby An important and powerful concept to understand in any programming language is looping. By using loops we can iterate through arrays and interact with each piece of data in the array until a certain condition is met. If you know how t...

Apr 13, 2022 · 5 min read · kadeesterline.hashnode.dev  
Read the article

-   [#ruby](https://hashnode.com/tag/ruby)
-   [#algorithms](https://hashnode.com/tag/algorithms)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

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

@kadeesterline

  
[View profile](https://hashnode.com/@kadeesterline)

Software Engineer

## Responses 1

Markdown supported · ⌘↵ to post

[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!
