cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
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
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
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
gallardet
Level III

Re: For loop with increments different of one

Thanks!