Comment by vbit
8 years ago
This applies to loops as well. Numbers are objects that accept the `timesRepeat:` message:
10 timesRepeat: [ n := n*2 ].
Not only that, you can send messages to blocks, to implement loops.
[ n < 10 ] whileTrue: [ n := n + 1 ]
Compare to Ruby:
The latter isn't possible "out of the box", but easy enough to implement:
Ruby syntax does get in the way of some of the more succint ways of defining control structures in Smalltalk, but the above shows some of the Smalltalk heritage of Ruby quite well, I think (though, while "10.times" is fairly idiomatic Ruby, implementing constructs like the one below certainly is not).