ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Display Number from For() Loop

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mac Lad
Display Number from For() Loop
on Jun 22, 2018 at 1:53:02 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;
}


Return to posts index

Dan Ebberts
Re: Display Number from For() Loop
on Jun 22, 2018 at 4:06:43 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



Return to posts index

Mac Lad
Re: Display Number from For() Loop
on Jun 23, 2018 at 12:02:33 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


Return to posts index


Kalleheikki Kannisto
Re: Display Number from For() Loop
on Jun 23, 2018 at 2:09:10 pm
Last Edited By Kalleheikki Kannisto on Jun 23, 2018 at 2:12:05 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]