xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

DO WHILE

Executes a block of statements while a condition is true.

Syntax

[DO] WHILE <Condition>
  <Statements>
  [EXIT]
  <Statements>
  [LOOP]
  <Statements>
END[DO]

Arguments

DO WHILE <Condition>
<Condition> is a logical expression which controls the DO WHILE loop. Statements within the loop are repeated until <Condition> results in .F. (false).
EXIT
The EXIT statement unconditionally terminates a DO WHILE loop. Program flow branches to the first statement following the ENDDO statement.
LOOP
The LOOP statement branches control unconditionally to the DO WHILE statement, i.e. to the begin of the loop.

Description

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>.

Info

See also:AEval(), BEGIN SEQUENCE, DbEval(), DO CASE, FOR, FOR EACH, IF, RETURN
Category: Control structures , Statements

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe