added #downTo:do:
authorClaus Gittinger <cg@exept.de>
Thu, 04 Oct 2001 16:44:13 +0200
changeset 6073 a2b1c61dae18
parent 6072 55858717097a
child 6074 d91c99700e3b
added #downTo:do:
Magnitude.st
--- a/Magnitude.st	Thu Oct 04 16:42:07 2001 +0200
+++ b/Magnitude.st	Thu Oct 04 16:44:13 2001 +0200
@@ -131,6 +131,17 @@
 
 !Magnitude methodsFor:'iteration'!
 
+downTo:stop do:aBlock
+    "For each element of the interval from the receiver down to the argument stop,
+     evaluate aBlock, passing the number as argument."
+
+    ^ self to:stop by:-1 do:aBlock
+
+    "
+     10 downTo:1 do:[:i | Transcript showCR:i].
+    "
+!
+
 to:stop by:incr do:aBlock
     "For each element of the interval from the receiver up to the argument stop, incrementing
      by step, evaluate aBlock passing the element as argument."
@@ -139,16 +150,22 @@
 
     tmp := self.
     (incr > 0) ifTrue:[
-	[tmp <= stop] whileTrue:[
-	    aBlock value:tmp.
-	    tmp := tmp+incr
-	]
+        [tmp <= stop] whileTrue:[
+            aBlock value:tmp.
+            tmp := tmp+incr
+        ]
     ] ifFalse:[
-	[tmp >= stop] whileTrue:[
-	    aBlock value:tmp.
-	    tmp := tmp+incr
-	]
+        [tmp >= stop] whileTrue:[
+            aBlock value:tmp.
+            tmp := tmp+incr
+        ]
     ]
+
+    "
+     1 to:10 do:[:i | Transcript showCR:i].
+     1 to:10 by:2 do:[:i | Transcript showCR:i].
+     10 to:1 by:-1 do:[:i | Transcript showCR:i].
+    "
 !
 
 to:stop by:incr doWithBreak:aBlock
@@ -221,9 +238,15 @@
 
     tmp := self.
     [tmp <= stop] whileTrue:[
-	aBlock value:tmp.
-	tmp := tmp+1
+        aBlock value:tmp.
+        tmp := tmp+1
     ]
+
+    "
+     1 to:10 do:[:i | Transcript showCR:i].
+     1 to:10 by:2 do:[:i | Transcript showCR:i].
+     10 to:1 by:-1 do:[:i | Transcript showCR:i].
+    "
 !
 
 to:stop doWithBreak:aBlock
@@ -308,5 +331,5 @@
 !Magnitude class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.15 2000-08-29 15:12:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.16 2001-10-04 14:44:13 cg Exp $'
 ! !