Please help in Program to swap adjacent elements of a Single Linked List by rearranging links

public static void swapValuesByLink(SinglyLinkedList l) {
SinglyLinkedList.Node temp,prev=l.head,tmp;
for(temp=l.head;temp!=null&&temp.next!=null;prev=tmp,temp=temp.next.next) {
tmp=temp.next;
System.out.println("temp is “+ temp+” prev is “+prev+” tmp is "+ temp.next);
temp.next.next=temp;
temp.next=tmp.next;
if(temp==l.head) {
l.head=tmp;
}{
prev.next=tmp;
}

  SinglyLinkedList.Node i=temp;
  temp=tmp;
  tmp=i;

}
}

Please help me. The above function causing an infinite loop but if I do dry run it seems okay to me. Please help.