Open In App

COBOL – Continue Statement

Last Updated : 24 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In simple terms think of the continue statement as a Gatekeeper who will open the gate for the people to come inside the premise to do their task. Similarly continue statement also transfers the control on the next COBOL statement for execution.

Syntax:

CONTINUE

Let’s take the example of Continue in Cobol for a better understanding of the concept.

Example:

Cobol




IDENTIFICATION DIVISION.
       PROGRAM-ID. DEMO1.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
           01 WALLET         PIC 9(05) VALUE ZERO.
           01 STD-VAL        PIC 9(05).
           01 COST           PIC 9(05).
           01 STD-QUANTITY   PIC 9(01) VALUE ZERO.
       PROCEDURE DIVISION.
           MOVE ZEROES TO WALLET.
           DISPLAY 'ADD MONEY TO WALLET'
           ACCEPT STD-VAL
           DISPLAY 'MONEY ADDED: 'STD-VAL.
           DISPLAY 'HOW MANY TICKET YOU WANT TO BUY 1 TICKET COST: 250'.
           ACCEPT STD-QUANTITY
           COMPUTE WALLET = WALLET + STD-VAL
           COMPUTE COST = 250 * STD-QUANTITY
             
           IF WALLET - COST >= 0
               CONTINUE
           ELSE
               DISPLAY 'INSUFFICIENT BALANCE'
               MOVE 16 TO RETURN-CODE
               GOBACK
               EXIT
           END-IF.
                 
           COMPUTE WALLET = WALLET - COST
           DISPLAY 'PURCHASE SUCCESSFUL BALANCE LEFT: ' WALLET.
             
           STOP-RUN.


Explanation:

There are 2 scenarios that will happen in the code, which will be governed by the statement IF WALLET – COST >= 0   CONTINUE meaning if the value in the wallet is greater than equal to the purchase it will make a successful transaction and deduct the money from the wallet and if the balance in the wallet is not enough it will exit with return code 16 and message ”INSUFFICIENT BALANCE’.

Case 1: Person adds enough money to wallet and makes a purchase.

Output:

Money  deducted

In the above example, you can see how the Continue statement moved the flow to make the transaction happen and update the value inside Variable WALLET and the program ends with return code 0.

Case 2: Person doesn’t add enough money to wallet and make a purchase 

Output:

Money not deducted

In this case, the program didn’t go through the transaction phase and ended with return code 16 and the message ‘INSUFFICIENT BALANCE’.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads