www.delorie.com/gnu/docs/smalltalk/gst_75.html   search  
 
Buy GNU books!


GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.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.
 
   Smalltalk at: #i put: (Interval from: 5 to: 10) !
   i printNl !
   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 printNl !
   i do: [:x| x printNl] !


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003