| xHarbour Reference Documentation > Statement Reference |
![]() |
![]() |
![]() |
Executes a block of statements while a condition is true.
[DO] WHILE <Condition> <Statements> [EXIT] <Statements> [LOOP] <Statements> END[DO]
The DO WHILE statement is a control structure that executes a block of statements repeatedly while a condition is true, or until the EXIT statement is executed. The logical expression <Condition> is evaluated as many times as the statements between DO WHILE and ENDDO are executed. When the ENDDO or LOOP statement is encountered, a next execution cycle begins with the evaluation of the <Condition> expression.
The EXIT statement terminates a DO WHILE loop unconditionally and control is branched to the nearest ENDDO statement without evaluating <Condition>.
| See also: | AEval(), BEGIN SEQUENCE, DbEval(), DO CASE, FOR, FOR EACH, IF, RETURN |
| Category: | Control structures , Statements |
// The example demonstrates a typical usage of a DO WHILE loop.
// A database file is scanned until the end-of-file is reached.
PROCEDURE Main
LOCAL aRecno := {}
USE Customer
DO WHILE ! Eof()
IF Customer->City = "New York"
AAdd( aRecno, Recno() )
ENDDO
SKIP
ENDDO
? Len( aRecno ), "customers in New York"
USE
RETURN
http://www.xHarbour.com