Preventing and diagnosing AdvPL loops
Makes progress, exit conditions and loop limits explicit.
Overview
Identify what changes the continuation condition before optimizing a loop. For query cursors, qualify Eof and DbSkip with the query alias even when the body positions another table. Loop can skip advancement at the end of the body; organize each path to advance or exit. This memory-only example has a work limit and a business condition that stops earlier. Diagnose with counters and technical identifiers without personal data; compare progress and check unlimited retries, locks and reentrant validation. (Sources: refs. 1–2.)
Commented example
#Include "Protheus.ch"
User Function Ed597()
Local nStep := 0
Local nLimit := 10
// Every iteration advances; the cap bounds the work.
While nStep < nLimit
nStep++
If nStep == 3
Exit
EndIf
EndDo
ConOut(nStep)
Return NilPrints 3 with explicit progress and exit. A cap does not replace error handling or cancellation. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- A counter cannot interrupt a blocking inner call. Measure the slow section and check each operation alias.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.