|
LOOPName:
The loop is terminated with and END OF LOOP (or END LOOP) command.
where <par> is a parameter that specifies the loop index variable; <start> is a number or parameter that is the value for <par> on the first iteration of the loop; <inc> is a number or parameter that <par> is incremented by after each iteration is completed; <stop> is a number or parameter that determines when the loop is terminated (i.e., when <par> exceeds this value, no more iterations are performed).
LOOP FOR K = START INC STOP LOOP FOR K = 10 -2 1
Note that Dataplot does not support what are referred to as WHILE (or DO WHILE or REPEAT UNTIL) loops in other languages. However, The BREAK LOOP command can be used to function much like a WHILE loop. So, although the following syntax is not supported
a similar result can be obtained with
LOOP FOR K = 1 1 1000000
IF A > 3
BREAK LOOP
END OF IF
This is demonstrated in the Program 2 example. Note:
This is demonstrated in the Program 3 example.
1994/02: Added BREAK LOOP command 2018/10: Added CONTINUE LOOP command
LET Y1 = NORMAL RANDOM NUMBER FOR I = 1 1 100
LET Y2 = EXPONENTIAL RANDOM NUMBERS FOR I = 1 1 100
LET Y3 = T RANDOM NUMBERS FOR I = 1 1 100
LET Y4 = CAUCHY RANDOM NUMBERS FOR I = 1 1 100
LET STRING T1 = NORMAL RANDOM NUMBERS
LET STRING T2 = EXPONENTIAL RANDOM NUMBERS
LET NU = 20
LET STRING T3 = T RANDOM NUMBERS
LET STRING T4 = CAUCHY RANDOM NUMBERS
LET X = SEQUENCE 1 1 100
MULTIPLOT 2 2
MULTIPLOT CORNER COORDINATES 0 0 100 100
LOOP FOR K = 1 1 4
TITLE ^T^K
HISTOGRAM Y^K
END OF LOOP
END OF MULTIPLOT
Program 2:
FEEDBACK OFF
. Computes Least Absolute Deviations fit using
. using iteratively re-weighted least squares.
. The following assumes that a string F has been defined before
. calling this macro to define the type of fit. E.g.,
. LET STRING F = FIT Y X
WEIGHT
^F
LET MAXITER = 10
LOOP FOR K = 1 1 MAXITER
LET RESOLD = RES
LET MED = MEDIAN RES
LET TEMP = ABS(RES - MED)
LET MAD = MEDIAN TEMP
LET S = MAD/0.6745
LET U = RES/S
LET TEMP = ABS(RES)
LET C = MEDIAN TEMP
LET TAG = ABS(Y - PRED)
LET WT = C/TAG SUBSET TAG > C
LET WT = 1 SUBSET TAG <= C
WEIGHTS WT
^F
.
LET DELTA = (RESOLD - RES)**2
LET NUM = SUM DELTA
LET NUM = SQRT(NUM)
LET DELTA2 = RESOLD*RESOLD
LET DENOM = SUM DELTA2
LET CONV = NUM/DENOM
IF CONV <= 0.0001
BREAK LOOP
END OF IF
END OF LOOP
Program 3:
let icnt = 0
loop for k = 1 1 10
let ival = mod(k,2)
if ival = 0
continue loop
end of if
let icnt = icnt + 1
let x(icnt) = k
let y(icnt) = k**2
end of loop
print x y
The following output is generated
------------------------------
X Y
------------------------------
1.00000 1.00000
3.00000 9.00000
5.00000 25.00000
7.00000 49.00000
9.00000 81.00000
Date created: 09/18/2024 |
Last updated: 09/18/2024 Please email comments on this WWW page to [email protected]. | ||||||||||