title: NetLogo foreach list
body: <p>I am trying to create a code that will allow me to get the who numbers of 10 turtles and store them in a list. However, the &quot;who&quot; number can only be added to the list if it has not been added to the list before.</p>
  <p>I have to use the &quot;foreach&quot; command to check if the number has already been added to the list.</p>
  <p>Any suggestions on how to do so?</p>
  <p>My code:</p>
  <pre><code>turtles-own [contact-list]
  
  to setup
    clear-all
    
    create-turtles 10 [
      set contact-list []
      print who
    ]
    
    reset-ticks
  end
  
  to go
    ask turtles [
      set contact-list lput [who] of one-of other turtles-here contact-list
      foreach contact-list[
        ; this is where the command goes
      ]
      print contact-list
    ]
  end
  </code></pre>