Unexpected behaviour within repeat loop
Posted: Sat Oct 25, 2008 5:08 am
I am encountering what to me seems strange behaviour within a repeat loop.
In the following script, put theta into fld "theta" does not result on display of theta until the script has exited the repeat loop. Even stranger, moving the line "put phi into fld "phi"" above "end repeat" seems to result in the script hanging. I don't see any reason why using a PUT command within a repeat loop should be illegal. What I would have expected is that the value of theta would have been updated each time the script loops through the outer repeat loop and that a similar result would have been obtained if the line "put phi into fld "phi"". Am i missing something important?
on mouseUp
global p, d, sumx, sumz, ax, az, Ao
put 0.01 into d
repeat with theta = 0 TO pi STEP d
repeat with phi = 0 TO 2*pi STEP d
put COS(theta)^4*SIN(theta) into az
put COS(phi)^2*COS(theta)^2*SIN(theta)^3 into ax
put sumz + az*d*d into sumz
put sumx + ax*d*d into sumx
end repeat
put phi into fld "phi"
Put theta into fld "theta"
end repeat
put (sumz-sumx)/(sumz+2*sumx) into Ao
put Ao into fld "answer"
end mouseUp
In the following script, put theta into fld "theta" does not result on display of theta until the script has exited the repeat loop. Even stranger, moving the line "put phi into fld "phi"" above "end repeat" seems to result in the script hanging. I don't see any reason why using a PUT command within a repeat loop should be illegal. What I would have expected is that the value of theta would have been updated each time the script loops through the outer repeat loop and that a similar result would have been obtained if the line "put phi into fld "phi"". Am i missing something important?
on mouseUp
global p, d, sumx, sumz, ax, az, Ao
put 0.01 into d
repeat with theta = 0 TO pi STEP d
repeat with phi = 0 TO 2*pi STEP d
put COS(theta)^4*SIN(theta) into az
put COS(phi)^2*COS(theta)^2*SIN(theta)^3 into ax
put sumz + az*d*d into sumz
put sumx + ax*d*d into sumx
end repeat
put phi into fld "phi"
Put theta into fld "theta"
end repeat
put (sumz-sumx)/(sumz+2*sumx) into Ao
put Ao into fld "answer"
end mouseUp