Sorry, imago's writeup is the most correct one, he merely failed to explicitly state that you test rigorously against NULL to make sure neither pointer goes off the list. What we want is a robust function capable of determining if any node in the list points to any previous node in the list.

Therefore we will need two pointers that traverse the list at different periods, and we will constantly test them against each other and NULL.

Here is the function in C++. Assuming a node structure similar to this:

struct Node
{
    int value;
    Node *next;
};
This function will detect any looping that occurs anywhere in the list:

bool CheckForLoop(Node *head)
{
    Node *node1 = head, *node2 = head;
    bool result, flag = false;

    while(flag == false)
    {
        if(node1->next == NULL) { flag = true; result = false; }
            else node1 = node1->next;

        if(node2->next == NULL) { flag = true; result = false; }
            else node2 = node2->next;

        if(node2->next == NULL) { flag = true; result = false; }
        else node2 = node2->next;

        if(node1 == node2) { flag = true; result = true; }
    }
    return result;
}