Firstly, I wasnβt sure what you meant by βDo loops in netlogo work, like labels in assembler so that it jumps to the first while the label marks it,β but now I suspect you're referring to that if you nest two loop constructs in NetLogo, the possible use of stop breaks you out of the outer loop, which is admittedly not what you expect.
To demonstrate:
to test-loop let i 0 loop [ set ii + 1 type (word "i" i " ") let j 0 loop [ set jj + 1 type (word "j" j " ") if j = 3 [ stop ] ] if i = 3 [ stop ] ] end
You will get this at the command center:
observer> test-loop i1 j1 j2 j3
I understand why this could be a problem. while in NetLogo , however, behaves as you expected:
to test-while let i 0 while [ i <= 3 ] [ set ii + 1 type (word "i" i " ") let j 0 while [ j <= 3 ] [ set jj + 1 type (word "j" j " ") ] ] end
And in the command center:
observer> test-while i1 j1 j2 j3 j4 i2 j1 j2 j3 j4 i3 j1 j2 j3 j4 i4 j1 j2 j3 j4
... so I donβt understand why you could not use two nested while .
Nicolas payette
source share