FOR ... ENDFOR Command Example

In Example 1, the numbers 1 through 10 are displayed.

Example 2 uses memory variables for the initial, final, and STEP values to display all even-numbered records from 2 through 10 in customer.

* Example 1
CLEAR
FOR gnCount = 1 TO 10
   ? gnCount
ENDFOR

* Example 2
SET TALK OFF
CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer  && Opens Customer table
STORE 2 TO gnI  && Initial value
STORE 10 TO gnJ  && Final value
STORE 2 TO K  && Step value
FOR gnCount = gnI TO gnJ STEP K
   GOTO gnCount  && Move record pointer
   DISPLAY company && Display company name
ENDFOR