FOR / NEXT Loops

FOR / NEXT loops provide the flexibility of varying parameters inside a loop.

Some cards in EDITFEKO implicitly use loops (such as when an FR card with multiple frequencies is used). This does not always provide the flexibility which may be required. For example, to change the material parameters inside the loop. Another example would be the use of a loop to create a complex geometry object(s).

For general loops, PREFEKO allows the construct:
!!for #var = #start to #end step #delta
!!next
where a simple example would be as follows:
** Loop for the relative permittivity
!!for #eps_r = 1 to 5 step 0.5
** Set material parameters
GF   0    1         #epsr
** Compute fields etc.
FE
** End of loop
!!next
The syntax requirements of FOR / NEXT loops are as follows:
  • The !! characters must be located in the first two columns of the line. This is followed by a number of optional spaces and the keyword FOR (it is not case sensitive, so also “For” or “for” are accepted).
  • The keyword FOR is followed by the name of the loop variable (starting with #).
  • Next follows an expression for the initial value of the loop (a constant, variable or formula).
  • This is followed by the keyword TO and the terminating value of the loop variable (again a constant, variable or formula).
  • The default increment of the loop variable is 1, but it can be changed by using the keyword STEP followed by an expression. Negative increments are allowed.
  • The loop is terminated by a line of the form !!NEXT (spaces are allowed between !! and NEXT but not before the !!). All instructions and input cards between !!FOR and !!NEXT are evaluated repeatedly inside the loop.
  • Loops can be nested.
A more complicated example:
#end = 3+sin(4)
!!for #x1 = sqrt(5) + 2*3 to 2*#end step -#end/10
!! for #x2 = 1.23 to 2*#x1 ** this is the inner loop
#x3 = #x1 + #x2
DP ....
.... (more commands)
!! next
!!nex