Well, by adding an extra element AFTER THE CURRENT ELEMENT in each iteration of the loop, you are thus ensuring that the end of the list is never reached! NextElement(mylist()) (in the While clause) will always return a non-zero result in your code!
You will have to rethink what it is you are trying to do.
Thanks srod. My purpose is to do a copy of a complexe linked list and append the copy at the end.
My idea was:
1. read out the actual list item
2. remember the pointer
3. add a new list item
4. go back to the pointer and continue looping
A workaround could be to copy existing linked list into a temporary local one and append the new stuff in a second step. But my attemp was to do it within one step.
*edit*: Your solution runs. Thanks. Optimized version:
Insert the elements above the current element, and you'll se that the loop exits. Another way would be to get the address of the last element before entering loop and check if the current element equals this. If it does you should exit the loop.
As it is now youl'll get the following added to the list:
- John
- Eric
- John-Copy
- Eric-Copy
- John-Copy-Copy
- Eric-Copy-Copy
- ... etc