Home Segments Index Top Previous Next

426: Mainline

You can iterate over the elements in a Set instance by using a do: message exactly like the do: message used with arrays, ordered collections, or bags:

Workspace
(Set new add: 570; add: 720; add: 640; add: 720; yourself) 
  do: 
  [:element | Transcript show: element printString; space] 
Transcript 
640 720 570  

Evidently, the set contains only three numbers: 640, 720, and 570. The attempt to add the second 720 comes to nothing, because sets contain no duplicates.