COBOL by Example: Paragraphs
Understanding paragraphs as the smallest named units of code in the PROCEDURE DIVISION consisting of user-defined names and executable sentences, implementing structured programming with PERFORM statements to execute paragraphs and return control, avoiding unstructured GO TO statements that create spaghetti code, and managing sequential paragraph execution with proper termination to prevent fall-through behavior.
Code
IDENTIFICATION DIVISION.
PROGRAM-ID. PARA-DEMO.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY "Start of Program".
PERFORM SECOND-PARA.
DISPLAY "End of Program".
STOP RUN.
SECOND-PARA.
DISPLAY "Inside Second Paragraph".Explanation
A PARAGRAPH is the smallest named unit of code within the Procedure Division. It consists of a user-defined name followed by a period, and then one or more sentences (instructions). Paragraphs are used to break down the program logic into small, manageable, and reusable chunks that can be called from other parts of the program.
Paragraphs can be executed using the PERFORM statement, which works like a function call. You can also use GO TO to jump to a paragraph, but this is generally discouraged in modern programming as it leads to spaghetti code that is hard to follow. PERFORM ensures structured programming by returning control to the caller after the paragraph finishes.
Just like sections, paragraphs execute sequentially. In this example, if you don't explicitly stop execution (e.g., with STOP RUN or EXIT PROGRAM), the code will continue to the next paragraph automatically. This fall-through behavior is a common source of bugs for beginners.

