Detect Loop In 2d Array