method to find loops in a linked list