Programing STATS commands 

There is a limited set of programing commands which can be used to automate the use of STATS commands.


Whereas there must be NO spaces in STATS commands, programing statements MUST be spaced out except when using STATS commands or expressions.

Square brackets, [ ], indicate optional syntax.


The start an end of a set of instructions must be stated explicitly.

Begin must be at the start of a program.

Finish must be at the end of a program.


= assigns a variable name to value.

The value may be an actual number, another variable or an expression created using standard BASIC syntax.

e.g. b = 2*c-d will assign the current value of the expression 2*c-d to the variable b


For variable name= starting value to final value [step step value]

This statement defines the start of a loop where the loop variable takes the specified values.

'Step' values can be fractional and negative. If no 'step' is included, it defaults to 1.

Loops may be nested.

e.g. For m = 1 to 5; will start a loop using m as the loop variable with initial value 1 which will increase by 1 each loop until a final value of 5 is exceeded.


This defines the end of a loop. When this position is reached, the loop variable is incremented by the 'step' value and checked against the final value defined in this loop's 'For' statement. If the end of the loop has been reached, the loop is terminated. Otherwise, the program loops back to the line after the 'For' statement.

Do ... While or Do ... Until loops can be faked by a For ... Next loop, although, with hindsight, it might have been easier to define a Do loop and fake a For ... Next!


If condition then

This statement checks the truth of the specified condition.

If it is True then the lines following the statement are processed until an 'Else' or 'Endif' statement is found. Otherwise, the lines following the corresponding 'Else' or 'Endif' statements are processed.

If a>= 7 then; will continue with the next lines if the value labeled a is currently greater than or equal to 7.


If an 'Else' statement is included, it is the lines following this which will be processed when the 'If' condition is False


If there is no 'Else' statement, the program jumps to the lines after 'Endif' when the 'If' condition is False.


' The single quote symbol allows you to add explanatory comments to your programs.

These can come at the end of a progam line e.g. For a = 1 to 7 'Loop seven times.

or have a line to themselves. e.g. 'The next section generates random integers.


The following senior school investigation is used as an example to illustrate the use of repetition.

"Investigate the range produced and the mean of the range when a set of normally distributed random numbers are generated with different Standard Deviations."

Using STATS commands alone, the following will produce the required information.


The process would then need to be repeated with the Standard Deviation in the 'random_n' command changed to 2, then 3, etc.

This calls for a program and a loop! (With comments added for clarity).

For a = 1 to 4 'Use a For loop to generate Standard Deviations.
clear_all 'Clear out the previous set of data.
random_n(50,a,50,1,4) 'Generate 50 random numbers with a mean of 50 and S.D. a in columns 1 to 4.
b_range(1,4,5) 'Find the range if the values in columns 1 to 4 and store the result in column 5.
c_mean(5,b) 'Find the mean of the ranges and store the result as b.
value(b) 'Display the mean

This will provide the required information but it can be made better by having it store the results and draw a best line through them.

a = 4 'Use a variable to define the number of loops.
st[1:6] = 0 'Store a zero in the first row of column 6
st[1:7] = 0 'and column 7 as the first data pair.
For b = 1 to a 'Use a For loop to generate Standard Deviations of 1 to a.
b_clear(1,5) 'Clear the working block of data, columns 6 & 7 must stay.
random_n(50,b,50,1,4) 'Generate 50 random numbers with a mean of 50 and S.D. b in columns 1 to 4.
b_range(1,4,5) 'Find the range if the values in columns 1 to 4 and store the result in column 5.
st[b+1:6] = b 'Store the Standard Deviation in column 6
c_mean(5,st[b+1:7]) 'and the mean of the ranges in column 7
best_line(axes,linear,6,7,7) 'Show the best straight line for the means plotted against the Standard Deviations.

I feel that the use of conditional statements is likely to be limited in the context of STATS.

The following example is given as a simple illustration of 'If ... then', 'Else' and 'Endif' for anyone not familiar with the structure.

For a = 1 to 5 'Use a For loop.
If a>2 then 'Start of the conditional statement.
b = 3 'Assign b the value 3 if the condition is True,
Else 'Otherwise,
b = 2 'assign it the value 2.
Endif 'The end of the conditional statement.
value(b) 'Display the value of b, (2, 2, 3, 3, 3)

It is possible to indent program statements to emphasise the structure by the use of spaces, (Tabs won't work), and the F10 key is programmed to add or insert a group of spaces into a line which has no effect on the execution of a program.

For a = 1 to 5
If a>2 then
b = 3
b = 2

It would be simple to extend the program facility to allow the use of any variable name; of different variable types and of extra programing statements. As mentioned previously, this has not been done because it would carry an overhead of processing time which will slow down the interpreter.

However, if you feel that extra facilities would be useful, please contact me.