Comprendre PERFORM en COBOL
Le PERFORM est une instruction fondamentale en COBOL qui permet d'exécuter des paragraphes ou des sections de manière répétée ou conditionnelle.
Syntaxe de base
000100
PERFORM
NOM-PARAGRAPHE
PERFORM avec TIMES
000200
PERFORM
NOM-PARAGRAPHE 5 TIMES
PERFORM avec UNTIL
000300
PERFORM
NOM-PARAGRAPHE UNTIL COMPTEUR > 10
Exemple complet
000400
IDENTIFICATION
DIVISION.
000500
PROGRAM-ID.
EXEMPLE-PERFORM.
000600
PROCEDURE
DIVISION.
000700
DEBUT.
000800
PERFORM AFFICHER-MESSAGE 3 TIMES.
000900
STOP RUN.
001000
AFFICHER-MESSAGE.
001100
DISPLAY "Bonjour le monde!".
Exercice pratique
Ă€ votre tour
Écrivez un programme COBOL qui utilise PERFORM pour afficher votre nom 5 fois.
Éditeur COBOL
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. VOTRE-PROGRAMME.
000300 PROCEDURE DIVISION.
000400 DEBUT.
000500 PERFORM AFFICHER-NOM 5 TIMES.
000600 STOP RUN.
000700
000800 AFFICHER-NOM.
000900 DISPLAY "Votre nom ici".
Cette instruction exécute le paragraphe
NOM-PARAGRAPHEune seule fois.Le point (
.) en fin de ligne marque la fin de l'instruction.