Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How can I continue/break a for loop from within two if statements.

  • How can I continue/break a for loop from within two if statements.

    Posted by Jacob Danell on May 12, 2014 at 4:45 pm

    Hi! I have for loop with one if inside and inside that if another if and I would need to continue the loop if the 2nd if is false.
    I searched some and didn’t find any solution except in javascript, being able to use goto. I tried in ExtendScript Toolkit and the word goto lit up blue but when I ran it it says “Illegal use of reserved word ‘goto’.
    This is my code in short way:

    function addToRenderQueue() {
    if (folder.exists) {
    *******
    for (var i = 0; selectedID.length > i; i++) {
    *******
    if (selectedCompItem instanceof CompItem) {
    *******
    } else {
    *******
    if (selectedCompItem.mainSource.file != undefined) {
    *******
    } else {
    *******
    goto endOfLoop;
    }
    }
    endOfLoop:
    }
    }
    }

    Jacob Danell replied 12 years ago 1 Member · 1 Reply
  • 1 Reply
  • Jacob Danell

    May 12, 2014 at 5:45 pm

    I found my solution. I put “endofloop:” before the loop I had to break trough and in my else I added “break endofloop;”

    function addToRenderQueue() {
    if (folder.exists) {
    *******
    for (var i = 0; selectedID.length > i; i++) {
    *******
    endOfLoop:
    if (selectedCompItem instanceof CompItem) {
    *******
    } else {
    *******
    if (selectedCompItem.mainSource.file != undefined) {
    *******
    } else {
    *******
    break endOfLoop;
    }
    }

    }
    }
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy