Proposal: JDK-8148917 Enhanced-For Statement Should Allow Streams
javalists at cbfiddle.com
Mon Mar 11 23:36:51 UTC 2019
Also, if the upper bound is an expression, the range() approach makes it clear that the upper bound expression is intended to be evaluated once.
> On Mar 11, 2019, at 4:07 PM, John Rose <john.r.rose at oracle.com <mailto:john.r.rose at oracle.com>> wrote:
> P.S. I also saw the fiery objections to the range() idiom, and I have
> to disagree with those disagreers! I prefer the range idiom to the
> multi-part for-init-test-step idiom, because counters are semantically
> *more complex* than ranges, from the viewpoints I typically use to
> reason about programs. (There are times when a separate counter
> state *is* preferable to me, but usually when there is some sort of
> extra "i += skip" side effect in the loop.) That's got to be a matter of
> taste. I suppose some people habitually reason about programs
> in lower-level terms, like x86 instructions, and there a counter is no
> more complex than a range; for those people there's no reason to
> learn a different concept than a for-loop. And surely there are other
> points of view that favor the good old for-loop-with-int-counter.
> I'm more tolerant of new-fangled range-based notations because they
> let me avoid having to reason about side-effect-laden entities
> like counters, and that feels like a good thing to me. Tastes vary.
More information about the core-libs-dev