COBOL Next Sentence
The NEXT SENTENCE statement transfers control to the next COBOL statement, which is immediately after the sentence ending with period.
It does not transfer control to the logically next COBOL verb.
The NEXT SENTENCE statement can be used anywhere in the programming construction like conditional statement or normal flow of program.
The NEXT SENTENCE statement used to change the flow of execution based on the condition passed to the logically next COBOL verb following the next period.
The NEXT SENTENCE has a impact on program flow which will skips the statements in between NEXT SENTENCE and period.
The NEXT SENTENCE will not come along with any other statement coded above or below.
Practical Example - NEXT SENTENCE:
Below example used to explain NEXT SENTENCE functionality
In the below example, if any student marks are less than 35 then the NEXT SENTENCE transfers the control to the immediate statement after the period(.)
If any student failed, then the below example will display message "STUDENT FAILED, NO PERCENTAGE CALCULATED"
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). 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 NEXT SENTENCE ELSE ADD STD-MARKS (STD-INDEX) TO TOTAL-MARKS SET STD-INDEX DOWN BY 1 END-IF END-PERFORM COMPUTE STD-PERCENT = TOTAL-MARKS/6 DISPLAY 'STUDENT PERCENTAGE : ' STD-PERCENT. IF I < 7 DISPLAY 'STUDENT FAILED, NO PERCENTAGE CALCULATED' END-IF. STOP RUN.
Difference between Files COBOL Continue Statement