|
Loops and simulations |
|
|
Commands ForEach [# of loops] ForEach [filespec, i. e. ”C:\data\DR*.txt”] ForEachSheet Next Regenerate Explanation The heart of many scripts is a loop. You can loop a certain number of times (for simulations), over all matching files (repeated importing), or over all sheets in a section (to print or export…). End the loop with a Next statement. You cannot nest loops. One common use of a Prism script is to do Monte Carlo analyses. First create a Prism file that uses the analysis ‘Simulate data with random scatter” to generate data, and links those simulated data to another analysis (say a nonlinear regression). Inside each loop, use the GoTo command to go to the analysis page that generates the data, and use the Regenerate command to create new ‘data’ (with different random scatter). Then go to the results, write out selected results, and use the Next command to loop again. See script example 2 at the beginning of this chapter. Inside a loop, you can use the expression ‘ %N’ which equals the current loop number. You could write the iteration number into an output file. When looping over a group of files. use %F to output the file name and %X to output the extension (without the period). In addition to looping a specified number of times (see the simulation section just above) you can loop over a set of files (see Script example 1 at the beginning of the chapter) or over all sheets in the current Prism section. |