HP3000-L Archives

March 1998, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Dan Bundus <[log in to unmask]>
Reply To:
Dan Bundus <[log in to unmask]>
Date:
Thu, 5 Mar 1998 11:00:36 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (75 lines)
Speaking of academics...

As we know, truly recursive applications make use of unique
local variable values in each recursive call; in COBOL this can
only be accomplished with a subprogram.  I experimented with
this concept a while back, and came up with this workable,
though simplistic example:  (All code in a single source file)

IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  GLOBAL-CTR     EXTERNAL  PIC 99.
01  RCURSV-CTR               PIC 99.
PROCEDURE DIVISION.
00-PROC.
   MOVE 0 TO GLOBAL-CTR,
             RCURSV-CTR.
   CALL "SUBPROG" USING BY CONTENT RCURSV-CTR.
   DISPLAY "----------------------".
   DISPLAY "GLOBAL-CTR==> " GLOBAL-CTR.
   DISPLAY "RCURSV-CTR==> " RCURSV-CTR.
   STOP RUN.

END PROGRAM MAIN.

IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPROG.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  GLOBAL-CTR     EXTERNAL  PIC 99.
LINKAGE SECTION.
01  RSV-CTR                  PIC 99.
PROCEDURE DIVISION USING RSV-CTR.
00-PROC.
   ADD 1 TO GLOBAL-CTR,
            RSV-CTR.
   DISPLAY "PRE-RECURS VALUE--> " RSV-CTR.
   IF RSV-CTR < 10
      CALL "SUBPROG" USING BY CONTENT RSV-CTR.
   DISPLAY "POST-RECURS VALUE-> " RSV-CTR.
   GOBACK.

Which when executed, displays...

PRE-RECURS VALUE--> 01
PRE-RECURS VALUE--> 02
PRE-RECURS VALUE--> 03
PRE-RECURS VALUE--> 04
PRE-RECURS VALUE--> 05
PRE-RECURS VALUE--> 06
PRE-RECURS VALUE--> 07
PRE-RECURS VALUE--> 08
PRE-RECURS VALUE--> 09
PRE-RECURS VALUE--> 10
POST-RECURS VALUE-> 10
POST-RECURS VALUE-> 09
POST-RECURS VALUE-> 08
POST-RECURS VALUE-> 07
POST-RECURS VALUE-> 06
POST-RECURS VALUE-> 05
POST-RECURS VALUE-> 04
POST-RECURS VALUE-> 03
POST-RECURS VALUE-> 02
POST-RECURS VALUE-> 01
----------------------
GLOBAL-CTR==> 10
RCURSV-CTR==> 00

Note, however, that values are passed but not returned.  (Still
REAL recursion??)

Dan Bundus
Oaksoft Consulting, Inc.

ATOM RSS1 RSS2