Scan
This loop command is designed for sequentially processing the records in a table. It automatically moves the record pointer forward each time through the loop and stops when it reaches the end of the table.
Usage |
SCAN [ Scope ] [ FOR lForCondition ] [ WHILE lWhileCondition ] [ NOOPTIMIZE ] Commands [ LOOP ] [ EXIT ] ENDSCAN |
DO WHILE .NOT. EOF() * Do some processing SKIP ENDDOWe tested empty loops, just going through a table from top to bottom, and found SCAN to be about twice as fast as the equivalent DO WHILE. Your mileage may vary.
SCAN always reselects the right work area (the one the loop started in) when it reaches ENDSCAN, so you don't need to reselect even if you've changed work areas inside the loop. We know a lot of people who do so anyway. There doesn't appear to be a performance penalty for this, so if you're the belt-and-suspenders type, go right ahead. |
Example |
USE Company * Loop through, printing fax if available and phone * number otherwise SCAN IF EMPTY(Fax) ? Phone ELSE ? Fax ENDIF ENDSCAN |
See Also |