VFP Tutorial - Scan ... EndScan loop

The scan loop is unique to the FoxPro family. It processes records in a table and executes the commands within the loop once for every record in the current work area:

* The staff table holds managers and employees
Use Staff In 0

* Modify salaries and bonuses
Scan
   If Title = 'manager'
     * Large rise and bonus for managers
     Replace Salary With Salary * 1.10
     Do PayBonus With ManagerID, 10000
   Else
     * Small rise and no bonus for the other employees
     Replace Salary With Salary * 1.02
   EndIf
EndScan

The code in this example will modify every record in the Staff table and reward the managers.

Notes

The simple Replace operation could have been done with a for clause but the Scan loop enables us to call the PayBonus procedure as well and to pass the current ManagerID across for each manager's record.

Back to FoxPro program control.


Introduction | Environment | Project | Tables | Forms | Navigation | Executable

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - The Goto statement

The truth about the FoxPro Goto statement

Read More

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Navigation

Navigating between records in Visual FoxPro

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro

Read More

Visual FoxPro Tutorial - Program control

Syntax for program control structures in Visual FOxPro

Read More