If p happens to be the last element in the list, then p.next.next does not exist. The if-statement ensures that we do not attempt to assign an undefined value to pointer p in line 5.
p
p.next.next