R
Roedy Green
In a for:each loop, sometimes you want to treat the first and or last
element specially.
The obvious way to handle is to revert to a for int i= loop and check
for special values of i.
You can keep the for:each style if you have a boolean first= true that
you set false to detect the first.
I don't know of an equivalent way to detect the last.
In the olden days I would have handled the first and last cases
outside the loop, with the loop running over the middle elements. You
can't do that with for:each.
What do you consider the best style to deal with this?
--
Roedy Green Canadian Mind Products
http://mindprod.com
For me, the appeal of computer programming is that
even though I am quite a klutz,
I can still produce something, in a sense
perfect, because the computer gives me as many
chances as I please to get it right.
element specially.
The obvious way to handle is to revert to a for int i= loop and check
for special values of i.
You can keep the for:each style if you have a boolean first= true that
you set false to detect the first.
I don't know of an equivalent way to detect the last.
In the olden days I would have handled the first and last cases
outside the loop, with the loop running over the middle elements. You
can't do that with for:each.
What do you consider the best style to deal with this?
--
Roedy Green Canadian Mind Products
http://mindprod.com
For me, the appeal of computer programming is that
even though I am quite a klutz,
I can still produce something, in a sense
perfect, because the computer gives me as many
chances as I please to get it right.