gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9


From: Bruce M. Axtens
Subject: Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9
Date: Fri, 31 May 2013 10:33:37 +0800
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Thunderbird/22.0

I've been fiddling with this a bit more and now have something that appears to work 90% of the time.
IDENTIFICATION DIVISION.
PROGRAM-ID. Random-mod-disps.

DATA DIVISION.
WORKING-STORAGE SECTION.
01    mod-disp      PIC Z9.
01    seed     PIC 999V999.
01    temp    PIC 999V.
01    div        PIC 99.
01    mod        PIC 99.
    88    mod-is-10 value 10.
PROCEDURE DIVISION.
Main.
    MOVE FUNCTION RANDOM(FUNCTION SECONDS-PAST-MIDNIGHT) TO seed.
    PERFORM FOREVER
        PERFORM Generate-And-Display-mod-disp

        IF mod-is-10
            EXIT PERFORM
        ELSE
            PERFORM Generate-And-Display-mod-disp
        END-IF
    END-PERFORM

    STOP RUN.
    .

Generate-And-Display-mod-disp.
    COMPUTE temp = FUNCTION RANDOM * 100.
    DIVIDE temp BY 20 GIVING div REMAINDER mod.
    MOVE mod TO mod-disp.
    DISPLAY mod " " mod-disp.
    .
  
Compiled with $ cobc -x -free -I/usr/local/include -L/usr/local/lib  breakloop.cob

The other 10% is where a run calculates a mod of 10 but does not exit the perform, viz
address@hidden ~/open-cobol-1.1
$ breakloop.exe
05  5
02  2
03  3
00  0
12 12
10 10
11 11
12 12
08  8
13 13
15 15
19 19
19 19
11 11
02  2
09  9
05  5
14 14
15 15
15 15
10 10

Please note the 6th line which says that mod contains 10 and mod-disp contains 10. Instead of terminating then, the program continues on until it hits another 10 10 pair and *then* it terminates.

What's going on here?

Bruce.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]