Q:

NETLOGO : Give command to ONLY turtles which variable fulfill the condition - after "foreach"

users,
I am trying to give command for turtles who have various variable. My agent called consumers. Each "consumers" has different need which represent by its color ( I use 14 color-base). When the number of consumers with particular color has reached > 10, I want them to change color into white. I use code below, resulting all of consumers change color into white. Though I only need "consumers" which satisfy the condition to change into white.
to cocreate-value
  let a count consumers with [ color = blue] 
  let b count consumers with [ color = gray] 
  let c count consumers with [ color = red]
  let d count consumers with [ color = orange]
  let e' count consumers with [ color = brown]
  let f count consumers with [ color = yellow]
  let g count consumers with [ color = green]
  let h count consumers with [ color = lime]
  let i count consumers with [ color = turquoise]
  let j count consumers with [ color = cyan]
  let k count consumers with [ color = sky]
  let l count consumers with [ color = violet]
  let m count consumers with [ color = magenta]
  let n count consumers with [ color = pink]

  ask consumers [set type-of-need ( list a b c d e' f g h i j k l m n ) ] 
  foreach type-of-need [
    if  ? > 10  [
        let z consumers with [ ? > 10] 
        ask z [ set color white ]
        ask consumers with [color = white] [set need? false]
   ]]
   end

Can someone show me the solution?
Thank you 

A:

Your problem is that your list is composed of numbers (the counts for each type of consumer) rather than the type-of-need themselves. You could see this by doing a print type-of-need after you create it. Let's say it looks like [5 12 4 ...]. Then you loop through this list of numbers and eventually get to one that is larger than 10. In the example, you now have ? = 12. Then the condition for creating the agentset z will be true for all consumers.
The following code is untested, but you need to list the types rather than the counts. Try something like this:
to cocreate-value
  let a count consumers with [ color = blue] 
  let b count consumers with [ color = gray] 

  ask consumers [set type-of-need ( list blue gray ) ] 
  foreach type-of-need [
    if  count consumers with [ color = ? ] > 10  [
        let z consumers with [ color = ? ] 
        ask z [ set color white ]
        ask consumers with [color = white] [set need? false]
   ]]
   end

