A WHILE clause causes a command to act on each record as long as the logical expression evaluates to true (.T.). The first time the expression evaluates to false (.F.), the command ceases without attempting any remaining records. This expression is typically used with a table that's been sorted or indexed on the field(s) included in the WHILE expression. For instance, the following example navigates an indexed table to locate the first record that meets the condition, then the REPLACE command acts on those records that meet the WHILE condition.

 CopyCode imageCopy Code
USE Mytable INDEX street
REPLACE street WITH "Maine" WHILE UPPER(street) = "MAIN"

You can use Scope, FOR, and WHILE expressions in the same Visual FoxPro command. For instance, the following examples store a new value in the status field of several records.

 CopyCode imageCopy Code
REPLACE ALL status WITH "Active" FOR total > 30 ;
   WHILE expd > {^1998/02/16}

When you specify both FOR and WHILE, the WHILE expression takes precedence and the FOR clause is used to filter the records selected by WHILE.

The following table lists commands in which you can use a WHILE clause.

Commands That Use WHILE Clauses

Expand imageSee Also