[Pharo-users] Interval form: x to: y when x > y - or how to count down...

Tim Mackinnon tim at testit.works
Fri Feb 22 09:57:55 EST 2019


I've just been caught out with Intervals - why can't you do: 
5 to: 1 do: [ :i | Transcript show: i printString]  (eg a negative interval)?

if you want to iterate down a series of numbers do you really have to do: 
5 to: 1 by: -1 do: […

I always assumed that if x > y the step was automatically -1 (but its not).

I asked on Discord - and someone pointed out that if you use variables it could be ambiguous - but is it really? I don’t know if other smalltalks do it this way (I vaguely recall Dolphin going down, but not sure).

Either way the Interval comment should mention this - and I’ll correct it when I get the wisdom of the crowd here.

Tim


More information about the Pharo-users mailing list