DTRHELP.HLB  —  Commands Statements Clauses, FOR Statement, Examples
       The following example assigns a value to the field PRICE for
       three yachts with prices equal to zero:

       DTR> READY YACHTS MODIFY
       DTR> SET NO PROMPT
       DTR> FIND FIRST 3 A IN YACHTS WITH PRICE = 0
       [3 records found]
       DTR> PRINT A

                                      LENGTH
                                       OVER
       MANUFACTURER   MODEL     RIG    ALL   WEIGHT BEAM  PRICE

        BLOCK I.    40         SLOOP   39    18,500  12
        BUCCANEER   270        SLOOP   27     5,000  08
        BUCCANEER   320        SLOOP   32    12,500  10

       DTR> FOR A
       CON> MODIFY USING PRICE = DISP * 1.3 + 5000
       DTR> PRINT A

                                      LENGTH
                                       OVER
       MANUFACTURER   MODEL     RIG    ALL   WEIGHT BEAM  PRICE

        BLOCK I.    40         SLOOP   39    18,500  12  $29,050
        BUCCANEER   270        SLOOP   27     5,000  08  $11,500
        BUCCANEER   320        SLOOP   32    12,500  10  $21,250

       DTR>

       The following example uses a variable to force an end to a FOR
       loop before all records in the record stream have been acted
       upon:

       DTR> READY YACHTS
       DTR> DECLARE A PIC 9.
       DTR> PRINT A

       A

       0

       DTR> SET NO PROMPT
       DTR> FOR YACHTS
       CON> BEGIN
       CON>   A = A + 1
       CON>   PRINT A, BOAT
       CON>   IF A = 5 THEN ABORT "END OF LOOP"
       CON> END

                                        LENGTH
                                         OVER
       A MANUFACTURER   MODEL     RIG    ALL   WEIGHT BEAM  PRICE

       1  ALBERG      37 MK II   KETCH   37    20,000  12  $36,951
       2  ALBIN       79         SLOOP   26     4,200  10  $17,900
       3  ALBIN       BALLAD     SLOOP   30     7,276  10  $27,500
       4  ALBIN       VEGA       SLOOP   27     5,070  08  $18,600
       5  AMERICAN    26         SLOOP   26     4,000  08   $9,895
       ABORT: END OF LOOP

       DTR>

       The following example contains a SORTED BY clause that allows the
       FOR loop to select records according to their length. The context
       variable X identifies the record stream in the FOR statement.

       DTR> READY YACHTS
       DTR> FOR FIRST 4 X IN YACHTS SORTED BY LOA
       CON> PRINT BUILDER, LOA

                    LENGTH
                     OVER
       MANUFACTURER  ALL

        WINDPOWER    16
        CAPE DORY    19
        ENCHILADA    20
        VENTURE      21

       DTR>

       The following example uses nested FOR loops to increase by one
       year the age of each child in the first two records of the domain
       FAMILIES:

       DTR> READY FAMILIES MODIFY
       DTR> PRINT FIRST 2 FAMILIES

                             NUMBER    KID
         FATHER     MOTHER    KIDS     NAME    AGE

       JIM        ANN           2   URSULA      7
                                    RALPH       3
       JIM        LOUISE        5   ANNE       31
                                    JIM        29
                                    ELLEN      26
                                    DAVID      24
                                    ROBERT     16

       DTR> SET NO PROMPT
       DTR> FOR FIRST 2 FAMILIES
       CON>   FOR KIDS
       CON>     MODIFY USING AGE = AGE + 1
       DTR> PRINT FIRST 2 FAMILIES

                             NUMBER    KID
         FATHER     MOTHER    KIDS     NAME    AGE

       JIM        ANN           2   URSULA      8
                                    RALPH       4
       JIM        LOUISE        5   ANNE       32
                                    JIM        30
                                    ELLEN      27
                                    DAVID      25
                                    ROBERT     17
Close Help