Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FOR loop re-evaluation
Message
De
23/01/2019 13:38:44
 
 
À
23/01/2019 12:20:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01665680
Message ID:
01665687
Vues:
75
>As I understand it, the FOR loop's TO range is evaluated at the start of the expression, and then not re-evaluated. Is there any way to make it be re-evaluated (a SYS() function or other setting)? Or do I need to switch to a DO WHILE loop and manually increment my loop variable?
>
>
LOCAL lnI
>CLEAR
>
>? "FOR loop:"
>lnI = 0
>FOR lnI = 1 TO test(lnI)
>    ? lnI
>NEXT
>
>? ""
>? "DO loop:"
>lnI = 1
>DO WHILE lnI < test(lnI)
>    ? lnI
>    lnI = lnI + 1
>    IF lnI >= 5
>        EXIT
>    ENDIF
>ENDDO
>
>FUNCTION test
>LPARAMETERS tnI
>    RETURN tnI + 1
>
I'd suggest using a DO WHILE loop as changing the loop boundaries in a FOR loop is usually considered bad form in most languages. In some languages the definition may state that doing so is considered an error -- but leaves it to the implementation on what actually happens (i.e. it may give runtime error, or it might not).
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform