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 |