GNU Smalltalk User’s Guide: Intervals

Next: , Previous: , Up: Code blocks (II)


6.7.2 Intervals

It is also possible to represent a range of numbers as a standalone object. This allows you to represent a range of numbers as a single object, which can be passed around the system.

 i := Interval from: 5 to: 10
 i do: [:x | x printNl]

As with the integer loops, the Interval class can also represent steps greater than 1. It is done much like it was for our numeric loop above:

 i := (Interval from: 5 to: 10 by: 2)
 i do: [:x| x printNl]

AltStyle によって変換されたページ (->オリジナル) /