Hello, task of the recursive function below is to analyse a network of of elements. The elements are characterized by a section no. 'iA' and an element no 'iM'. Each element can have up to 8 inlets and outlets. IANMSA is the number of oulets of an element. The circuitry of the elements is stored in the arrays IAANRA, IAMNRA. At runtime the error 'Active Do-loop index altered' occurs.
Recursive Function CFBCheckLoop(iA, iM) RESULT(KFehl)
Integer, Intent(in) :: iA, iM
Integer :: KFehl
Integer :: iT, iA1, iM1
if (iA == WSMem%IAVB) then
KFehl = 0
else if (kkdms(iA,iM) == 506) then
KFehl = 1
else
do iT = 1, IANMSA(iA, iM)
iA1 = IAANRA(iA, iM, iT)
iM1 = IAMNRA(iA, iM, iT)
if (iA1 == 0) then
KFehl = 2
else
KFehl = CFBCheckLoop(iA1, iM1)
end if
if (KFehl > 0) Exit
end do
end if
End Function CFBCheckLoop
Obviously the inner instance of the recursive function changes the index 'iT' of the calling instance of the function. The variable iT is declared inside the function. Normally each instance of an recursive function should have its own protected internal variables, which cannot be changed from outside. They should also be protected against changes from another instance of the function. I have used recursive functions like this in Delphi/Pascal many times without any problems.