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 While Function

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

Another way to iterate is with the While function. This function takes only two arguments: the test, and the body. So, if you want to use a counter, index, or flag variable in either argument, you need to initialize those before you call the While function. JMP evaluates the first argument and interprets it as a Boolean result in order to determine if the iteration should continue. If the result is true, then the While function continues with the iteration. If it's false, then the While function ends iteration and the script continues with whatever code follows the While function. JMP evaluates the second argument next. This code is usually considered to be the body of the iteration, and JMP evaluates this code every time. Because there's no separate update argument, part of this code should update the counter, index, or flag variable for the next iteration. Let's look at an example. In this code, c is a counter or index and it's initially set to Not Done is the flag variable, which is initially set to true. So in the While function, JMP first evaluates not Done and interprets it as a Boolean result. If not Done is true, then the function continues. Then, the body includes the main work of the iteration- launching the Distribution platform - and then also updates the not Done variable based on a Boolean comparison. In the code shown here, JMP compares the number of columns in the data table to the current value of the counter, AND updates the counter. The comparison returns a if there are more columns in the data table, and returns a zero when all the columns have been evaluated. This result is stored in not Done, which is evaluated at the beginning of the next iteration. Note that the Post Increment operator returns its current value before incrementing -- so the last piece of the code could be written N Col greater than c, semicolon, c plus-plus, and it would do the exact same thing.