Powered By Blogger Submit Your Site To The Web's Top 50 Search Engines for Free! Online Marketing

Subscribe Now

Friday, November 11

Cobol Nested IF-ELSE

Contoh program cobol dengan menggunakan gabungan dari If Then Else dan Evaluate.

       IDENTIFICATION DIVISION. 
       PROGRAM-ID.     ANOTHER-EXAMPLE.
       AUTHOR.         AKIRA.

      *  Program ini menggambarkan struktur kondisi IF Bersarang.
      *  perbandingan dengan sintaks EVALUATE, kondisi IF Bersarang
      *  dan EVALUATE menunjukkan sebuah logika yang sama

       ENVIRONMENT DIVISION. 

       DATA DIVISION. 

       WORKING-STORAGE SECTION. 

       01 KBD-ENTRY PIC X.

       PROCEDURE DIVISION. 

       MAIN-LINE. 
           PERFORM DO-SETUP.
           PERFORM DO-NESTED-IF.
           PERFORM DO-EVALUATE.
           STOP RUN.

       DO-SETUP.
           DISPLAY 'Enter a digit '.
           ACCEPT KBD-ENTRY.

       DO-NESTED-IF.
           IF KBD-ENTRY = '1'
              DISPLAY 'Freshman'
           ELSE IF KBD-ENTRY = '2'
                   DISPLAY 'Sophomore'
                ELSE IF KBD-ENTRY = '3'
                        DISPLAY 'Junior'
                     ELSE IF KBD-ENTRY = '4'
                             DISPLAY 'Senior'
                          ELSE IF KBD-ENTRY = '5'
                                  DISPLAY 'Graduate'
                               ELSE
                                  DISPLAY 'Undefined code'
                               END-IF
                          END-IF
                     END-IF
                END-IF
           END-IF.

       DO-EVALUATE.
           EVALUATE KBD-ENTRY
               WHEN '1'    DISPLAY 'Freshman'
               WHEN '2'    DISPLAY 'Sophomore'
               WHEN '3'    DISPLAY 'Junior'
               WHEN '4'    DISPLAY 'Senior'
               WHEN '5'    DISPLAY 'Graduate'
               WHEN OTHER  DISPLAY 'Undefined code'
           END-EVALUATE.

Related Posts


0 Comments:

Post a Comment

Popular Posts This Months

Related Posts Plugin for WordPress, Blogger...