Question: I've been using this post ([how to do replacing-item in use nested list](https://stackoverflow.com/questions/23182872/how-to-do-replacing-item-in-use-nested-list)) as a guide to work out how to replace items in a list, that meet a given criteria. 

Specifically, I want to replace all zeros in a list with the value = 0.5. However, the code I've come up with only seems to replace the first zero in the list and I can't seem to work out why. 

This is my code:

```
to-report A-new-list-without-zeros [old new the-list]
 let A-index-list n-values length the-list [?]
 ( foreach A-index-list the-list
   [ if ?2 = old  
      [ report replace-item ?1 the-list new ]
   ])
 report the-list
end

```

And this is what happens:

```
observer> show A-new-list-without-zeros 0 0.5 [0 1 0 5 5 0]
observer: [0.5 1 0 5 5 0]

```

Any help would be much appreciated! Thanks

Answer: 
Anytime you use `report`, it exits the procedure and reports the output at that point. The quick fix using your code is to change the `report` line in your if statement so that it replaces the item at the current index:

```
to-report A-new-list-without-zeros [old new the-list]
 let A-index-list n-values length the-list [?]
 ( foreach A-index-list the-list
   [ if ?2 = old  
      [ set the-list replace-item ? the-list new ]
   ])
 report the-list
end

observer> print A-new-list-without-zeros  0 0.5 [ 0 1 0 5 5 0 ] 
[0.5 1 0.5 5 5 0.5]

```
This task is more easily accomplished with `map` than `foreach`.

NetLogo 6 syntax:

```
to-report A-new-list-without-zeros [old new the-list]
  report map [[x] -> ifelse-value (x = old) [new] [x]] the-list
end

```

NetLogo 5 syntax:

```
to-report A-new-list-without-zeros [old new the-list]
  report map [ifelse-value (? = old) [new] [?]] the-list
end

```