in reply to foreach only for a section of a list
You could ...
- store the last element in a variable; compare it on each iteration; if same, exit loop (not good if there are duplicates); or,
- copy|slice n-1 elements in another array to itierate over; or,
- better yet, use a counter to keep track of the current (elememt of the) array index, either via explicit C-loop or separately maintained one.