[prev] 71 [next]

Exercise #10: Traversing a linked list

What does this code do?

1  p=list
2  while p≠NULL do
3  |  print p.value
4  |  if p.next≠NULL then
5  |     p=p.next.next
6  |  else
7  |     p=NULL
8  |  end if
9  end while

What is the purpose of the conditional statement in line 4?