Hi,

Op 9 nov. 2012 om 20:19 heeft Stephan Hennig <[email protected]> het 
volgende geschreven:

> Am 09.11.2012 09:58, schrieb Taco Hoekwater:

> What is the advantage of this to the naive
> 
>  local n = head
>  while n do
>    ...
>    n = n.next
>  end
> 
> ?

Not a lot, but some people prefer the writing style with for loops. Running 
speed
is comparable for both styles of looping, if I recall correctly. 

> 
>  a guard missing in the while loop that stops when t == nil.
> 

It is in the code, of course. The explanation was getting long, so I skipped 
that.

> |     return t
> |   end
> | \stoptyping
> 
> Again, what is the advantage of this to the naive
> 
>  local n = head
>  while n do
>    if n.id == <id> then
>      ...
>    end
>    n = n.next
>  end


traverse_id really is faster, because the internal lookups are much faster than 
the repeated node.id and node.next calls. But still, it is mostly about style.

Best wishes,
Taco

Reply via email to