Let's say that we have an array with n elements (n > 0).
We would like to output a list of those elements, with a separator between them.
A common approach to this problem is:
foreach item
(
output item
output separator
)
trim last separator
But it seems a bit messy to have to do that.
Another approach would be:
check that there is at least one element
loop
(
output element
next element, or break if no more elements
output separator
)
But I am not sure that it will always work.
Do you see other clever ways to do that, for example in C, C++?