Moves the record pointer through the currently selected table and executes a block of commands for each record that meets the specified conditions.
SCAN [NOOPTIMIZE] [Scope] [FOR lExpression1] [WHILE lExpression2] [Commands] [LOOP] [EXIT] ENDSCAN
- Prevents Rushmore Query Optimization of SCAN. For more information, see SET OPTIMIZE Command and Using Rushmore Query Optimization to Speed Data Access.
- Specifies a range of records to be scanned. Only the records within the range are scanned. The scope clauses are: ALL, NEXT nRecords, RECORD nRecordNumber, and REST. For more information on scope clauses, see the Scope Clauses online topic. The default scope for SCAN is all records (ALL).
- FOR lExpression1
- Executes commands only for records for which lExpression1 evaluates to true (.T.). Including the FOR clause lets you filter out records you don't want scanned. Rushmore optimizes a query created with SCANВ ...В FOR if lExpression1 is an optimizable expression. For best performance, use an optimizable expression in the FOR clause. For more information, see SET OPTIMIZE Command and Using Rushmore Query Optimization to Speed Data Access.
- WHILE lExpression2
- Specifies a condition whereby the commands are executed for as long as lExpression2 evaluates to true (.T.).
- Specifies the Visual FoxPro commands to be executed.
- Returns control directly back to SCAN. LOOP can be placed anywhere between SCAN and ENDSCAN.
- Transfers program control from within the SCANВ ...В ENDSCAN loop to the first command following ENDSCAN. EXIT can be placed anywhere between SCAN and ENDSCAN.
- Indicates the end of the SCAN procedure.
SCAN automatically advances the record pointer to the next record that meets the specified conditions and executes the block of commands.
You can place comments after ENDSCAN on the same line. The comments are ignored during program compilation and execution.
SCANВ ...В ENDSCAN ensures that, upon reaching ENDSCAN, Visual FoxPro reselects the table that was current when the SCANВ ...В ENDSCAN loop began.
The following example uses a SCANВ ...В ENDSCAN loop to display all the companies in Sweden.
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE customer && Opens Customer table CLEAR SCAN FOR UPPER(country) = 'SWEDEN' ? contact, company, city ENDSCAN