LOOP#
The most powerful form of generation is achieved through loops. This form corresponds to the FORTRAN DO-Loops or to the FOR NEXT loops of BASIC. The loop is initiated by the record LOOP and terminated by the record ENDLOOP. A loop is executed as many times as determined by the number following LOOP (Default 9999). It may also be terminated if the expression following ENDLOOP becomes zero or negative. If the name of a variable is given instead of the number after the LOOP, then the number of elements contained in that variable will be used.
Loops can be nested up to 32 levels, containing any number of input elements. If LOOP is not followed by a number, it will be performed at most 9999 times.
Each loop construction must not exceed 255 lines. Multiple records, however, can be entered
at the same line (separated by ;
). If you still need more than 256 lines you have to specify
before the first LOOP.
LET#LOOPSIZE number_of_lines
It is possible to store the index of the loop in a variable, if the name is appended to the LOOP keyword. The index starts counting at zero. The variable may be changed within the loop, but it will be restored after evaluation of the terminating condition in each cycle. Generation of nodes and springs on a semicircle at a distance of 30 degrees.
LET#1 1 , LET#2 0.
LOOP 7
NODE #1 COS(#2) SIN(#2)
SPRI #1 #1 DX COS(#2) DY SIN(#2) CP 1.E5
LET#1 #1+1
LET#2 #2+30.
ENDLOOP
Instead of LOOP 7
/ ENDLOOP
you could use LOOP / ``ENDLOOP #2 < =180
. With an endloop
condition one can leave a loop prematurely.
Example for two-level generation:
LOOP#1 3
TXB ADEF #1+1
LOOP 2
TXB BDIV 0.5 #1+1
TXB 0.2 1
ENDLOOP
ENDLOOP
creates:
ADEF 1
BDIV 0.5 1
0.2 1
0.5 1
0.2 1
ADEF 2
BDIV 0.5 2
0.2 1
0.5 2
0.2 1
ADEF 3
BDIV 0.5 3
0.2 1
0.5 3
0.2 1
If you want to run a loop over all elements of an array, this may be done by giving only the
name of the array (without the #
):
LET#A 10,22,34,55,76,83
LOOP#1 A ! Only the name, #A would be the value 10!
NODE #1+1 X #A(#1)
ENDLOOP
With a small extension it is also possible to store the number of elements in a variable, where the value of 0 is obtained if the variable does NOT exist:
LOOP#NUM DEF(A)
ENDLOOP
Loops in CADINP
To be finished with
ENDLOOP
The input
LOOP nn
defines the number of loops.The maximum number of loops is limited to 999, which is also the default setting in case no
nn
is set.
Hint
In case it is necessary to have more than 999 loops, it is possible to nest several loops.
Instead of a number nn it is also possible to use a CADiNP variable. If this variable is defined as an array the number of loops is equal to the length of the array.
LET#FELD 3,4,1,5,7,2
LOOP#N FELD
@KEY LC_CTRL #FELD(#N)
!...
ENDLOOP
With
LOOP#variable
a counting variable can be defined. The first value starts with=0
.With
ENDLOOP
constraint it is possible to create specific break inside the loop. Usually the loop will be used as long as the constraint condition is true.