Anonymous user
Loops/With multiple ranges: Difference between revisions
→{{header|Smalltalk}}
Line 1,732:
Transcript show:'prod = '; showCR:prod</lang>
The above creates a temporary "collection of ranges" and enumerates that, which might be inconvenient, if the collections are huge.
<br>
Of course, we definitely don't want to retype the loop body
and we usually don't want to the code to be non-local (i.e. define another method for it).
<br>That's what blocks (aka lambdas or anonymous functions) are perfect for:
<lang smalltalk>prod := 1.
sum := 0.
Line 1,764:
Transcript show:'prod = '; showCR:prod</lang>
As
<lang smalltalk>...
{
|