Find limit of recursion: Difference between revisions
Content added Content deleted
(demonstrating better handling of stack-overflow exception) |
(A better way of doing it ... from a thread I started on comp.lang.cobol) |
||
Line 202: | Line 202: | ||
Thanks to Brian Tiffin for his [http://www.opencobol.org/modules/newbb/viewtopic.php?viewmode=thread&topic_id=254&forum=1&post_id=1312#1312 demo code on opencobol.org's forum] |
Thanks to Brian Tiffin for his [http://www.opencobol.org/modules/newbb/viewtopic.php?viewmode=thread&topic_id=254&forum=1&post_id=1312#1312 demo code on opencobol.org's forum] |
||
==A more 'canonical' way of doing it== |
|||
from Richard Plinston on [http://groups.google.com/group/comp.lang.cobol/browse_thread/thread/bc8574c6452a7da7# comp.lang.cobol] |
|||
{{works with|OpenCOBOL 1.1}} |
|||
<lang cobol> IDENTIFICATION DIVISION. |
|||
PROGRAM-ID. recurse RECURSIVE. |
|||
DATA DIVISION. |
|||
WORKING-STORAGE SECTION. |
|||
01 Starter PIC S9(8) VALUE 1. |
|||
PROCEDURE DIVISION. |
|||
Program-Recurse. |
|||
CALL "recurse-sub" USING Starter |
|||
STOP RUN. |
|||
IDENTIFICATION DIVISION. |
|||
PROGRAM-ID. recurse-sub. |
|||
DATA DIVISION. |
|||
WORKING-STORAGE SECTION. |
|||
LINKAGE SECTION. |
|||
01 Countr PIC S9(8). |
|||
PROCEDURE DIVISION USING Countr. |
|||
Program-Recursive. |
|||
DISPLAY Countr |
|||
ADD 1 TO Countr |
|||
CALL "recurse-sub" USING Countr |
|||
EXIT PROGRAM. |
|||
END PROGRAM recurse-sub. |
|||
END PROGRAM recurse. </lang> |
|||
Compiled with <pre>cobc -x -g recurse.cbl</pre> gives |
|||
<pre>... |
|||
+00000959 |
|||
+00000960 |
|||
+00000961 |
|||
+00000962 |
|||
+00000963 |
|||
+00000964 |
|||
recurse.cbl:19: Attempt to reference unallocated memory (Signal SIGSEGV) |
|||
Abnormal termination - File contents may be incorrect</pre> |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |