Notifications
Clear all

[Closed] while exp1 OR exp2 do ()… should it work?

Hi, I’m new to “while” loops and I can’t find a way to make it work based on two expressions:

I have a MultiArray with two numbers each, and a TESTarray with a list of 5 numbers.
I want the script to tell me if the TESTarray contains any of the two arrays.

It’s a simple test but to avoid getting an error because the While loops goes beyond the number of Arrays in MultiArray, I want the loop to stop if INCR goes over the number of arrays in MultiArrays (MultiArray.count)
But it seemed to ignore that expression and continue until it gives me an error because I went over MultiArray.count.

It doesn’t stop the script from continuing to work after but that’s quite ugly.
Any ideas why it seems to ignore that expression?
Thanks!


MultiArray= #(#(0,1),#(6,8),#(20,30))

TESTarray=#(0,3,30,4,22)
INCR=1
scoref1=0
scoref2=0

while (scoref1+scoref2)<2 or INCR<=MultiArray.count do (
scoref1=0
scoref2=0
print (“INCR1=”+INCR as string)
for f=1 to TESTarray.count do (
if TESTarray[f]==MultiArray[INCR][1] then scoref1=1
if TESTarray[f]==MultiArray[INCR][2] then scoref2=1
)
INCR+=1
print (“INCR_after=”+INCR as string)
)

print “:::While stopped:::”

if (scoref1+scoref2==2) then print “It’s here” else print “It’s not here”

2 Replies

While loop should only run if both expressions are true, so you need to use and instead of or


(
found = false
for val in MultiArray while not found where findItem TESTarray val[1] > 0 and findItem TESTarray val[2] > 0 do found = true
format "%
" found
)

Ok that’s beautiful.
3 lines vs 10 and it works.
Thanks Serejah, you opened up my mind, I guess I have a pretty long road before me before writing optimized scripts ^^.
Best.