Category:Smalltalk: Difference between revisions
Content added Content deleted
m (→Literals) |
|||
Line 380: | Line 380: | ||
As mentioned above, these are defined as messages and their implementation is found in the corresponding receiver classes. The following is only a tiny subset - there are virtually hundreds of uses of blocks for control structures in the system. |
As mentioned above, these are defined as messages and their implementation is found in the corresponding receiver classes. The following is only a tiny subset - there are virtually hundreds of uses of blocks for control structures in the system. |
||
Typical are: |
Typical are: |
||
<lang smalltalk> |
<lang smalltalk>boolean ifTrue: [ block providing value if boolean is true ] |
||
boolean ifTrue: [ block providing value if boolean is true ] |
|||
boolean ifFalse: [ block providing value if boolean is false ] |
boolean ifFalse: [ block providing value if boolean is false ] |
||
Line 389: | Line 388: | ||
[ block for condition ] whileTrue: [ block to be looped over ] |
[ block for condition ] whileTrue: [ block to be looped over ] |
||
n timesRepeat: |
n timesRepeat: [ block to be looped over ] |
||
start to: stop do: [:i | block to be looped over with index ] |
start to: stop do: [:i | block to be looped over with index ] |
||
collection do: [:el | block to be evaluated for each element ] |
collection do: [:el | block to be evaluated for each element ] |
||
</lang> |
|||
collection reverseDo: [:el | block to be evaluated for each element ]</lang> |
|||
=== Exception Handling === |
=== Exception Handling === |