Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
gallardet
Level III

For loop with increments different of one

I have a script which creates graphs of x (time) with respect to two consecutive columns (x). I pretend that "i" instead of increasing one by one, I do it two by two. 

This is part of the script: 

For( i = 2, i <= N Items( numericColNames )-1, i++,

 

When I change the iteration term to i+2 the script it enter in an loop without end

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: For loop with increments different of one

++ is a postfix operator that has the effect of incrementing in place.

 

There is no general purpose postfix operator to increment by an arbitrary value. Instead you'll need to use the assignment operator (=) to assign the result back to your counter:

 

for(i=1, i<=20, i=i+2,
	show(i)
);

in the log you'll get:

/*:
//:*/
for(i=1, i<=20, i=i+2,
	show(i)
);
/*:

i = 1;
i = 3;
i = 5;
i = 7;
i = 9;
i = 11;
i = 13;
i = 15;
i = 17;
i = 19;

 

-Jeff

View solution in original post

2 REPLIES 2
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: For loop with increments different of one

++ is a postfix operator that has the effect of incrementing in place.

 

There is no general purpose postfix operator to increment by an arbitrary value. Instead you'll need to use the assignment operator (=) to assign the result back to your counter:

 

for(i=1, i<=20, i=i+2,
	show(i)
);

in the log you'll get:

/*:
//:*/
for(i=1, i<=20, i=i+2,
	show(i)
);
/*:

i = 1;
i = 3;
i = 5;
i = 7;
i = 9;
i = 11;
i = 13;
i = 15;
i = 17;
i = 19;

 

-Jeff

View solution in original post

Highlighted
gallardet
Level III

Re: For loop with increments different of one

Thanks!
Article Labels