Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Display Number from For() Loop

  • Display Number from For() Loop

    Posted by Mac Lad on June 22, 2018 at 1:53 pm

    Hi Peoples,
    First of all, I am new to expressions. My goal is to display numbers between 0 and given input i.e. “a” on a new line(one below other). I did success to display initial number but my For() don’t iterate.
    The code I tried is below for the source text

    var text= ” “;
    var i;
    var a=5
    for (i=0; i<=a; i++) {
    text = “n=” + i + “\n”;
    break;
    }

    Kalleheikki Kannisto replied 7 years, 11 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    June 22, 2018 at 4:06 pm

    This probably isn’t exactly what you’re looking for, but it should get you closer:


    var txt= "n=";
    var i;
    var a=5
    for (i=0; i<=a; i++) {
    txt += i + "\n";
    }
    txt

    Dan

  • Mac Lad

    June 23, 2018 at 12:02 pm

    Thank You, Dan…! Some changes to expression, made it worked as I needed
    But still, don’t understand why we use “txt+=”.
    Below is the changed Expression
    var txt= “”;
    var i;
    var a=5
    for (i=0; i<=a; i++) {
    txt += “n=” + i + “\n”;
    }
    txt

  • Kalleheikki Kannisto

    June 23, 2018 at 2:09 pm

    “txt+=” is shorthand for “txt = txt +”
    If you don’t add to the existing text, the text gets overwritten with the value during each loop iteration, i.e. you only get the last value from the loop in the end.

    Kalleheikki Kannisto
    Senior Graphic Designer

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