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


GNU Smalltalk User's Guide

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

4.7.1 Integer loops

Integer loops are constructed by telling a number to drive the loop. Try this example to count from 1 to 20:
 
   1 to: 20 do: [:x | x printNl ] !

There's also a way to count up by more than one:
 
   1 to: 20 by: 2 do: [:x | x printNl ] !

Finally, counting down is done with a negative step:
 
   20 to: 1 by: -1 do: [:x | x printNl ] !


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