Adan
Adan

Reputation: 3

Netlogo: how to access current item while looping through a list?

I'm new to netlogo and I'm trying to iterate through a list. After some research I discovered I'd have to use a question mark (?) to access the current item. I tried it, but it gave me the following error: nothing named '?' has been defined. This is (a part of) my current code:

let klist (list k1 k2 k3 k4)
foreach klist [
  if opdracht = ? [set kans kans + 1]]

How do I access the current item?

Upvotes: 0

Views: 320

Answers (1)

Charles
Charles

Reputation: 4168

Your code should work in NetLogo 5.3.1, but if you are using NetLogo 6.0, the foreach syntax has changed to employ anonymous reporters. In 6.0 the code would be:

foreach klist [[k] ->
  if opdracht = k [set kans kans + 1]
]

Charles

Upvotes: 1

Related Questions