Block.st
changeset 1211 c5bdb3fc3cb4
parent 1189 b8400ee170c6
child 1254 48c2748b5197
equal deleted inserted replaced
1210:b2fbf119dbbd 1211:c5bdb3fc3cb4
   662      [n printNewline] doWhile:[ (n := n + 1) <= 5 ]
   662      [n printNewline] doWhile:[ (n := n + 1) <= 5 ]
   663     "
   663     "
   664 !
   664 !
   665 
   665 
   666 loop
   666 loop
   667     "repeat the receiver forever (should contain a return somewhere).
   667     "repeat the receiver forever 
   668      Inspired by a corresponding Self method."
   668      (the receiver block should contain a return somewhere).
       
   669      The implementation below was inspired by a corresponding Self method."
   669 
   670 
   670     self value.
   671     self value.
   671     thisContext restart
   672     thisContext restart
   672 
   673 
   673     "
   674     "
   674      |n|
   675      |n|
   675 
   676 
   676      n := 1.
   677      n := 1.
   677      [
   678      [
   678 	n printNewline.
   679         n printNewline.
   679 	n >= 10 ifTrue:[^ nil].
   680         n >= 10 ifTrue:[^ nil].
   680 	n := n + 1
   681         n := n + 1
   681      ] loop
   682      ] loop
   682     "
   683     "
       
   684 
       
   685     "Modified: 18.4.1996 / 13:50:40 / cg"
   683 !
   686 !
   684 
   687 
   685 loopWithExit
   688 loopWithExit
   686     "the receiver must be a block of one argument.  It is evaluated in a loop forever, 
   689     "the receiver must be a block of one argument.  It is evaluated in a loop forever, 
   687      and is passed a block, which, if sent a value:-message, will exit the receiver block, 
   690      and is passed a block, which, if sent a value:-message, will exit the receiver block, 
   703      ] loopWithExit
   706      ] loopWithExit
   704     "
   707     "
   705 !
   708 !
   706 
   709 
   707 repeat
   710 repeat
   708     "repeat the receiver forever - same as loop, for ST-80 compatibility"
   711     "repeat the receiver forever - same as loop, for ST-80 compatibility.
       
   712       (the receiver block should contain a return somewhere)."
   709 
   713 
   710     self value.
   714     self value.
   711     thisContext restart
   715     thisContext restart
       
   716 
       
   717     "Modified: 18.4.1996 / 13:50:55 / cg"
   712 !
   718 !
   713 
   719 
   714 valueWithExit
   720 valueWithExit
   715     "the receiver must be a block of one argument.  It is evaluated, and is passed a block,
   721     "the receiver must be a block of one argument.  It is evaluated, and is passed a block,
   716      which, if sent a value:-message, will exit the receiver block, returning the parameter of the 
   722      which, if sent a value:-message, will exit the receiver block, returning the parameter of the 
   717      value:-message. Used for premature returns to the caller.
   723      value:-message. Used for premature returns to the caller.
   718      Taken from a manchester goody (a similar construct also appears in Self)."
   724      Taken from a manchester goody (a similar construct also appears in Self)."
   719 
   725 
   720     ^ self value: [:exitValue | ^exitValue]
   726     ^ self value:[:exitValue | ^exitValue]
   721 
   727 
   722     "
   728     "
   723      [:exit |
   729      [:exit |
   724 	1 to:10 do:[:i |
   730         1 to:10 do:[:i |
   725 	    Transcript showCr:i.
   731             Transcript showCr:i.
   726 	    i == 5 ifTrue:[exit value:'thats it']
   732             i == 5 ifTrue:[exit value:'thats it']
   727 	].
   733         ].
   728 	'regular block-value; never returned'
   734         'regular block-value; never returned'
   729      ] valueWithExit
   735      ] valueWithExit
   730     "
   736     "
       
   737 
       
   738     "Modified: 18.4.1996 / 13:51:38 / cg"
   731 !
   739 !
   732 
   740 
   733 whileFalse
   741 whileFalse
   734     "evaluate the receiver while it evaluates to false (ST80 compatibility)"
   742     "evaluate the receiver while it evaluates to false (ST80 compatibility)"
   735 
   743 
  1034 ! !
  1042 ! !
  1035 
  1043 
  1036 !Block class methodsFor:'documentation'!
  1044 !Block class methodsFor:'documentation'!
  1037 
  1045 
  1038 version
  1046 version
  1039     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.50 1996-04-16 13:42:16 cg Exp $'
  1047     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.51 1996-04-18 12:17:36 cg Exp $'
  1040 ! !
  1048 ! !
  1041 Block initialize!
  1049 Block initialize!