000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.   PRMDISRB.
000300 AUTHOR.       Ryan Brooks.
000400 DATE-WRITTEN. MAR 2017 
000500 DATA DIVISION. 
000600 WORKING-STORAGE SECTION.
000700
000800 01 ANY-KEY                  PIC X(01).
000900 01 RANGE-START     PIC 999  VALUE 002.
001000 01 RANGE-END       PIC 999  VALUE 999.
001100 01 FLAG PIC 999.
001200 01 REM PIC 999.
001300 01 RES PIC 999.
001400 01 NUMBER1 PIC 9999.
001500 01 NUMBER2 PIC 999.
001600  
001700 PROCEDURE DIVISION.
001800 0000-DRIVER.
001900     DISPLAY "Ryan Brooks".
002000     display "List of Prime Numbers to 999".
002100     PERFORM 1200-WANT-TO-START
002200     Display "Displaying primes from " RANGE-START " to "
002300     RANGE-END.
002400     PERFORM 1000-PRIME-LOOP VARYING NUMBER1 FROM RANGE-START by 1
002500       UNTIL NUMBER1 > RANGE-END.
002600     PERFORM 1100-WANT-TO-EXIT.
002700     GOBACK.
002800     
002900 1000-PRIME-LOOP.
003000     MOVE 0 TO FLAG.
003100     PERFORM 1010-PRIME-LOOP-2 VARYING NUMBER2 FROM 2 BY 1
003200         UNTIL NUMBER2 > NUMBER1 - 1.
003300     IF FLAG = 0
003400         DISPLAY NUMBER2.
003500     
003600 1010-PRIME-LOOP-2.
003700     DIVIDE NUMBER1 BY NUMBER2 GIVING RES REMAINDER REM.
003800     IF REM = 0
003900         MOVE NUMBER1 TO FLAG.
004000     
004100 1100-WANT-TO-EXIT.
004200     display "There you go.  All 168 primes between 1 and 1000."
004300     display "Press any key to exit."
004400     ACCEPT ANY-KEY.
004500     
004600 1200-WANT-TO-START.
004700     display "Ready to start? Press any key to begin."
004800     ACCEPT ANY-KEY.