EXIT Command

Exits a DO WHILE, FOR, or SCAN loop.

EXIT

Remarks

EXIT transfers control from within a DO WHILE ... ENDDO, FOR ... ENDFOR, or SCAN ... ENDSCAN loop to the command immediately following ENDDO, ENDFOR, or ENDSCAN.

Example

In the following example, the number of products in stock priced over 20 dollars is totaled in the DO WHILE loop until the end of the file (EOF) is encountered. The DO WHILE loop is exited and the total is displayed.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE products  && Opens Products table
SET TALK OFF
gnStockTot = 0

DO WHILE .T.     && Beginning of loop
   IF EOF( )
      EXIT
   ENDIF
   IF unit_price < 20
      SKIP
      LOOP
   ENDIF
   gnStockTot = gnStockTot + in_stock
   SKIP
ENDDO  && End of loop

CLEAR
? 'Total items in stock valued over 20 dollars:'
?? gnStockTot 

See Also

DO WHILE ... ENDDO | FOR EACH ... ENDFOR | FOR ... ENDFOR | SCAN ... ENDSCAN