cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

Using the For Function

Started ‎11-08-2022 by
Modified ‎11-08-2022 by
View Fullscreen Exit Fullscreen

So, the For function provides the most general form of iteration. This function has four required arguments, and each one is a JSL expression. And as usual, these four arguments are separated by commas. JMP evaluates the first argument to the For function only once. Generally, you use this first argument to initialize a variable that you can use as a counter, or index, in each iteration, but you can use it for anything that has to occur at the beginning, before the first iteration, and then never again. If you need to, you can use the semicolon operator to glue together multiple functions for this, or any, argument to the For function. JMP evaluates the second argument at each iteration and interprets it as a Boolean result. Typically, you use it to test for the continuation of the iteration, but again- you can use it for anything that has to happen before each iteration. If the result of this test is true, then the For function continues. If the result is false, then the For function ends iteration, and the script continues with whatever code follows the For function. One more thing about this argument -- if you're iterating over a large number of columns or other items, consider counting before calling the For function. You can store the result of N Col or another counting function in a variable, and then use that variable for the Boolean comparison, instead of counting at each iteration. JMP evaluates the fourth argument next. This code is usually considered to be the body of the iteration, and JMP evaluates it in every iteration. Finally, JMP evaluates the third argument after each iteration. You usually use it to update the counter, or index, but you can use it for anything that has to happen after each iteration. The result of this update is typically used by the second argument- the Boolean test--to determine if the iteration should continue. The plus-plus is the operator for the Post Increment function -- it adds one in-place to a variable, so in this example, the value of c is incremented by one.