Condividi tramite


WHILE Clauses

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.

USE Mytable INDEX street
LOCATE FOR UPPER(street) = "MAIN"
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.

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

AVERAGE

COUNT

RECALL

BLANK

DELETE

REPLACE

BROWSE

DISPLAY

REPLACE FROM ARRAY

CALCULATE

EXPORT

REPORT

CHANGE

LABEL

SCAN ... ENDSCAN

COPY TO ARRAY

LIST

SORT

COPY TO

LOCATE

SUM

See Also

Reference

LOCATE Command

REPLACE Command (Visual FoxPro)

Other Resources

Field and Record Manipulation

Data Manipulation