Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SCAN FOR ... WHILE
Message
De
14/05/1999 13:56:14
 
 
À
14/05/1999 13:41:35
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00219112
Message ID:
00219128
Vues:
25
>>I've been using this technique for a while. I thought that the SCAN FOR would start at the top of the file and act as a filter only looking at records that meet the condition and the WHILE would cause the loop to end as soon as its condition was false.
>>
>>This is just a bogus example to illustrate the point.
>>
>>
>>
>>lnInvoiceHdrId = Invoice.iInvoiceHdrId
>>
>>llTableUpdateOk = .T.
>>
>>SELECT InvoiceDtl
>>SCAN FOR InvoiceDtl.iInvoiceHdrId = lnInvoiceHdrId WHILE ;
>>         llTableUpdateOk
>>     llTableUpdateOk = TABLEUPDATE( .F., .F., "InvoiceDtl" )
>>
>>ENDSCAN
>>
>>
>>
>>I thought that this would start at the top of the file and find all Invoice details that matched that Id and continue until it hits the end of the file or when the tableupdate fails.
>>
>
>Nope - the WHILE clause takes precedence here, since it expects to evaluate this for the current record. A better construct, or at least a more consistant one would be:
>
>
llTableUpdate = .F.  && nothing was updated yet
>SCAN FOR InvoiceDtl.iInvoiceHdrId = lnInvoiceHdrId
>     llTableUpdateOk = TABLEUPDATE( .F., .F., "InvoiceDtl" )
>     IF ! llTableUpdate
>         EXIT
>     ENDIF
>ENDSCAN
>
>>Similaray SCAN has an implicit WHILE NOT EOF() by itself.
>>
>>So does the SCAN WHILE without a FOR start at the top of the file or does it start from the current record positioning and move forward?

Thanks for the info.

I was afraid of that. The code I'm actually working on would have many exit points and I was trying to avoid that. Would it be better to add a GO TOP before the start of the scan?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform