In this topic, we described about the CONTINUE Statement with detailed example.
The CONTINUE statement transfers the control to the immediate COBOL statement comes next in the program flow. The CONTINUE statement is a no operation or do-nothing statement. CONTINUE indicates no executable instruction is present. CONTINUE transfers the control to the logically next COBOL verb.
CONTINUE statement allows to code with other statements like conditional statements or imperative statements.
- The CONTINUE is called as DO NOTHING Statement.
- CONTINUE is used to specify that there are no statements to be executed.
- CONTINUE Statement can be used anywhere where conditional statements or imperative statements used.
- CONTINUE will allow where the other statements coded above or below.
Practical Example - CONTINUE:
Below example will display the percentage if student passed all subjects or displays how many subjects failed
In the below example, If any student marks are below 35 while adding the marks to calculate percentage, CONTINUE will simply pass the control to next iteration without interrupting the process.
IDENTIFICATION DIVISION. PROGRAM-ID. PERFTIMI. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 STD-DET OCCURES 6 TIMES INDEXED BY STD-INDEX. 05 STD-MARKS PIC 9(03). 01 TOTAL-MARKS PIC 9(03) VALUE ZERO. 01 STD-PERCENT PIC 9(03).9(02). 01 I PIC 9(01). 01 J PIC 9(01) VALUE ZERO. PROCEDURE DIVISION. MOVE ZEROES TO TOTAL-MARKS. PERFORM VARYING I FROM 1 BY 1 UNTIL I > 6 SET STD-INDEX TO 1 ACCEPT STD-MARKS (STD-INDEX) IF STD-MARKS (STD-INDEX) < 35 CONTINUE ELSE ADD STD-MARKS (STD-INDEX) TO TOTAL-MARKS SET STD-INDEX DOWN BY 1 COMPUTE J = J + 1 END-IF END-PERFORM. IF J < 6 COMPUTE J = I -(J + 1) DISPLAY 'STUDENT FAILED IN 'J 'SUBJECTS ELSE COMPUTE STD-PERCENT = TOTAL-MARKS/6 DISPLAY 'STUDENT PERCENTAGE : ' STD-PERCENT. END-IF. STOP RUN.