Structured programming principle: Which construct is forbidden by the principles of structured programming?
-
AWHILE–DO
-
BGOTO
-
CIF–THEN–ELSE
-
DDO–WHILE
-
ENone of the above
Answer
Correct Answer: GOTO
Explanation
Introduction / Context:Structured programming advocates building programs from a small set of well-defined control structures to improve readability, maintainability, and correctness. Understanding which constructs fit this paradigm is essential.
Given Data / Assumptions:
- Structured constructs include sequence, selection, and iteration.
- GOTO introduces arbitrary jumps that can create “spaghetti code”.
- We assume standard imperative languages as context.
Concept / Approach:
Structured programming replaces unrestrained jumps with structured loops and conditionals. WHILE–DO, DO–WHILE, and IF–THEN–ELSE fit within these constructs. GOTO undermines structure by enabling non-local, unstructured control flow.
Step-by-Step Solution:
List structured constructs: sequence, IF–THEN–ELSE, WHILE/DO loops.Identify outlier: GOTO provides unconditional jump without block structure.Select GOTO as forbidden by structured programming principles.Verification / Alternative check:
Programming methodology literature encourages eliminating GOTO in favor of structured alternatives, allowing easier reasoning and formal verification.
Why Other Options Are Wrong:
- WHILE–DO, DO–WHILE: Structured loops; encouraged.
- IF–THEN–ELSE: Core selection construct; encouraged.
- None of the above: Incorrect because GOTO is indeed discouraged/forbidden by the principle.
Common Pitfalls:
Believing GOTO is never used; in rare low-level scenarios or generated code it appears, but structured design avoids it in source-level logic.
Final Answer:
GOTO