Notifications
Clear all
[Closed] increment nested loop parent
Jun 29, 2011 5:15 am
Hello!
I have a script that is like this
for i = 0 to myParent-1 do --there is 1 parent
(
getChildCount
for j in childCount-1 do --there are 6 children
(
if myThing(j).name == "hello, " then myVal1 == j.name
if myThing(j).name == "you" then myVal2 == j.name
if myThing(j).name == "are" then myVal3 == j.name
if myThing(j).name == "slow at this" then myVal4 == j.name
if myVal1 !=undefined and myVal2 !=undefined and myVal3 !=undefined and myVal4 !=undefined then print "hello"
)
)
it prints hello 3 times because of the 6 children, which is 2 times too many. I would like the parent to increment when all the values have been satisfied. Is there some code for “goto next parent item” I can use here?
Thanks!
I eagerly await denisT to turn this into one line of code…
3 Replies
Jun 29, 2011 5:15 am
You need to break the second loop at that point so just type “exit” where you need it.
That way, you return to the first loop and go at it again.
if myVal1 !=undefined and myVal2 !=undefined and myVal3 !=undefined and myVal4 !=undefined then print "hello"[B] else exit[/B]
Jun 29, 2011 5:15 am
it’s pseudo code, isn’t it?
but…
when you have multiple choice condition is better to use case expression:
case myThing(j).name of
(
"hello": ...
...
)
if one condition is right you don’t need to check another
if a condition might match several patterns i would do it this way:
patterns = #(a, b, c, ...)
matched = undefined
for p in patterns while matched == undefined where my_value <matches pattern> p do matched = p
if matched != undefined do <whatever i want>