2 ms·
Time to take another look... ...hey, for loops that take just a single integer and implicitly loop from 1. Interesting. Just checked my (Objective-)C loops, a
by mpweiher 8y ago
Time to take another look...
...hey, for loops that take just a single integer and implicitly loop from 1. Interesting.
Just checked my (Objective-)C loops, and of the 500 with
for (i=
440 start with
for (i=0;
That's 88%. So looping on integers that implicitly forms a range starting from 0 seems like a reasonable addition for Objective-Smalltalk. "Looping" is already defined as higher order functions on collections and ranges, so all we need to do is map the number to the appropriate range and done.
-(void)do:aBlock
{
[[@(0) to:[self sub:@(1)]] do:aBlock];
}
Try it out:
> 4 do:[ :i | stdout println:i ]
0
1
2
3
Nice. Thank you, BETA!