This function is showing time limit exceeded

acc. to me it should properly detect if there is a loop in current linked list
bool detectLoop(Node* head)
{
if(head->next==NULL)
return false;
if(head->next->next==NULL)
return false;
Node* temp=head->next->next;
while(head->data!=temp->data || temp->data!=NULL || head->data!=NULL){
if(temp->next==NULL)
return false;
if(temp->next->next==NULL)
return false;
temp=temp->next->next;
head=head->next;
}
if(head->data == temp->data){
return true;
}
return false;
// your code here
}

@akshitmehta both head and temp should start simultaneously!
so initialize temp with head!