# Strange errors with the combination of foreach and ask-concurrent

**URL:** <https://forum.netlogo.org/t/strange-errors-with-the-combination-of-foreach-and-ask-concurrent/785>\
**Category:** Bug Reports\
**Created:** [April 1, 2026, 2:31pm UTC](https://forum.netlogo.org/t/strange-errors-with-the-combination-of-foreach-and-ask-concurrent/785 "2026-04-01T14:31:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrkramer\_wageningen](https://forum.netlogo.org/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@mrkramer\_wageningen](https://forum.netlogo.org/u/mrkramer_wageningen)\
**Post date:** [April 1, 2026, 2:31pm UTC](https://forum.netlogo.org/t/strange-errors-with-the-combination-of-foreach-and-ask-concurrent/785/1 "2026-04-01T14:31:43Z")

</div>

As reported in [a question about turtle buttons and ask-concurrent](https://forum.netlogo.org/t/relation-between-turtle-buttons-and-ask-concurrent/784), the combination of `foreach` and `ask-concurrent` is broken.  
I know: the documentation warns about potentially broken `ask-concurrent` – so no guarentee.

The error messages do not seem to make sense. Therefore, I still report the problem.

See the accompanying text file for a description of steps to reproduce the various error messages and other behavior – expected or unexpected.

[ask-concurrent.txt](https://forum.netlogo.org/uploads/short-url/yVJFgSbp5hOLsPXvIhzHDXDgiyZ.txt) (5.1 KB)

---

<div class="post-metadata">

**Author:** ![mrkramer\_wageningen](https://forum.netlogo.org/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@mrkramer\_wageningen](https://forum.netlogo.org/u/mrkramer_wageningen)\
**Post date:** [April 1, 2026, 2:34pm UTC](https://forum.netlogo.org/t/strange-errors-with-the-combination-of-foreach-and-ask-concurrent/785/2 "2026-04-01T14:34:32Z")

</div>

Oh, I forgot to mention that there is a work-around:  
using `repeat` and indexing instead of `foreach`

---

<div class="post-metadata">

**Author:** ![ERSUCC](https://forum.netlogo.org/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@ERSUCC](https://forum.netlogo.org/u/ERSUCC)\
**Post date:** [April 12, 2026, 10:48pm UTC](https://forum.netlogo.org/t/strange-errors-with-the-combination-of-foreach-and-ask-concurrent/785/3 "2026-04-12T22:48:46Z")

</div>

Hi Mark,

Thank you for the bug report. You’re right that `ask-concurrent` has some intriguing issues, but since it’s no longer a supported primitive, it’s unlikely that we’ll be able to put enough development time into it to fix all the related problems. If you really need this behavior, it is possible to replicate the behavior of `ask-concurrent` in pure NetLogo code, although it’s a bit more verbose. You would need to manually split up your code block into sections as described in the documentation of `ask-concurrent`, and then run a normal `ask` on each section. For example, consider the following code:

```netlogo
ask-concurrent turtles [
  fd 1
  setxy random-xcor random-ycor
]

```

The equivalent “serial ask” would be:

```netlogo
ask turtles [fd 1]
ask turtles [setxy random-xcor random-ycor]

```

Isaac B.

---

<div class="post-metadata">

**Author:** ![mrkramer\_wageningen](https://forum.netlogo.org/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@mrkramer\_wageningen](https://forum.netlogo.org/u/mrkramer_wageningen)\
**Post date:** [April 13, 2026, 10:02am UTC](https://forum.netlogo.org/t/strange-errors-with-the-combination-of-foreach-and-ask-concurrent/785/4 "2026-04-13T10:02:32Z")

</div>

Hi Isaac,

Thank you for your answer.  
I understand that this does not have priority.

For equivalent code using `ask` instead of `ask-concurrent`, this is a challenge when the code under `ask-concurrent` contains loops and calls to other procedures, and local variables.

When the code does not use recursion – other than tail-end recursion – it is always possible in theory.  
But still, it will be quite a puzzle.  
I’m not asking the NetLogo team to solve this for me 😉
