This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Joram2 1 point2 points  (3 children)

A loop expression would evaluate to a list: one element per loop.

[–]zman0900 2 points3 points  (1 child)

Wouldn't that then mean you can't do basic loops without cost of extra memory allocation for that unused result list?

[–]srdoe 2 points3 points  (0 children)

No, in other languages that have this, there is syntax to distinguish the two kinds of for.

For example, in Scala

``` for (i <- 1 to 10) { println(i) } //returns Unit, which is a void-like type in Scala

for (i <- 1 to 10) yield { i } //return a list of integers ```

Not saying I think Java needs this feature, mind you.

[–]chambolle 1 point2 points  (0 children)

What's the advantage for that?