Summary -

In this topic, we described about the NEXT SENTENCE Statement with detailed example.

The NEXT SENTENCE statement transfers control to the next COBOL statement that immediately after the sentence ending with period. A sentence is a group of COBOL statements ended with a period.

Syntax -

NEXT SENTENCE

Rules -

  • The NEXT SENTENCE statement can use anywhere in the programming construction of the PROCEDURE DIVISION.
  • The NEXT SENTENCE statement used to change the flow of execution based on the condition.
  • The NEXT SENTENCE has a impact on program flow that skips the statements in between NEXT SENTENCE and period.
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"

Code -


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.