# How to end the BFS traversal at will( RGL)

**URL:** <https://www.ruby-forum.com/t/how-to-end-the-bfs-traversal-at-will-rgl/131193>\
**Category:** Rails\
**Created:** [March 6, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/how-to-end-the-bfs-traversal-at-will-rgl/131193 "2008-03-06T20:47:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [March 6, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/how-to-end-the-bfs-traversal-at-will-rgl/131193/1 "2008-03-06T20:47:24Z")

</div>

Hi,

I am using RGL for some of the graph implementations. My requirements is  
such that I need to find out all nodes that are at distance less than  
3.

For this, I thought of traversing the graph using BFS and stop the  
traversal when i reach 4th level. But how do I do this?

regards,  
Sandeep G
