📜  gnucobol exit (1)

📅  最后修改于: 2023-12-03 15:15:21.109000             🧑  作者: Mango

GNUCobol Exit

Introduction

GNUCobol Exit is a powerful feature of the GNUCobol programming language. It allows programmers to exit from a cobol program at a specific point or condition. This can be useful when dealing with exceptional situations or when a certain condition is met during program execution.

Usage

To use the GNUCobol Exit feature, you can use the following syntax:

EXIT PROGRAM

This statement will terminate the execution of the cobol program and return control back to the operating system or calling program.

EXIT PROGRAM WITH CODE n

This statement will terminate the program with an exit code 'n'. The exit code can be used to indicate the status of the program execution.

Examples

Here are some examples of how you can use the GNUCobol Exit feature:

Example 1: Simple Exit
IDENTIFICATION DIVISION.
PROGRAM-ID. EXIT-EXAMPLE.

PROCEDURE DIVISION.
    DISPLAY "Hello, GNUCobol Exit!".
    EXIT PROGRAM.

This example demonstrates a simple usage of the GNUCobol Exit feature. The program will display "Hello, GNUCobol Exit!" and then exit.

Example 2: Exit with Code
IDENTIFICATION DIVISION.
PROGRAM-ID. EXIT-CODE-EXAMPLE.

PROCEDURE DIVISION.
    DISPLAY "This program will exit with code 5".
    EXIT PROGRAM WITH CODE 5.

This example shows how to exit a program with a specific exit code. In this case, the program will exit with exit code 5 after displaying the message "This program will exit with code 5".

Example 3: Conditional Exit
IDENTIFICATION DIVISION.
PROGRAM-ID. CONDITIONAL-EXIT.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  flag  PIC X VALUE 'N'.

PROCEDURE DIVISION.
    IF flag = 'Y'
        DISPLAY "Flag is set. Exiting program."
        EXIT PROGRAM
    ELSE
        DISPLAY "Flag is not set. Continuing program."
    END-IF.

    ...

    EXIT PROGRAM.

In this example, the program will check the value of the flag variable. If the flag is set to 'Y', the program will display a message and exit immediately. Otherwise, it will continue executing the rest of the program and eventually exit.

Conclusion

The GNUCobol Exit feature is a powerful tool that allows programmers to control the flow of their cobol programs. It can be used to gracefully exit a program, indicate the status of the program execution, or handle exceptional situations.