Moves the record pointer through the currently selected table and executes a block of commands for each record that meets the specified conditions.
Syntax
SCAN [NOOPTIMIZE]
[Scope] [FOR lExpression1] [WHILE lExpression2]
[Commands]
[LOOP]
[EXIT]
ENDSCAN
Arguments
NOOPTIMIZE
Prevents Rushmore optimization of SCAN.
For more information, see SET OPTIMIZE and "Understanding Rushmore Technology" in Chapter 15, Optimizing Applications, in the Programmer's Guide.
Scope
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 and "Understanding Rushmore Technology" in Chapter 15, Optimizing Applications, in the Programmer's Guide.
WHILE lExpression2
Specifies a condition whereby the commands are executed for as long as lExpression2 evaluates to true (.T.).
Commands
Specifies the Visual FoxPro commands to be executed.
LOOP
Returns control directly back to SCAN. LOOP can be placed anywhere between SCAN and ENDSCAN.
EXIT
Transfers program control from within the SCAN ... ENDSCAN loop to the first command following ENDSCAN. EXIT can be placed anywhere between SCAN and ENDSCAN.
ENDSCAN
Indicates the end of the SCAN procedure.
Remarks
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.