In programming languages, the keyword 'break' (to exit a loop or switch immediately) is used in which of the following?
-
AFortran 77
-
BPascal
-
CC
-
Dnone of the above
-
ECOBOL
Answer
Correct Answer: C
Explanation
Introduction / Context:Control-flow statements vary across languages. The 'break' statement is widely associated with C and its derivatives (C++, Java, JavaScript) to terminate loops or switch-case blocks immediately. Identifying its origin helps map concepts across languages.
Given Data / Assumptions:
- Fortran 77: uses DO loops and arithmetic IF/GO TO; no 'break' keyword.
- Pascal: uses 'exit' or structured control like 'while', 'repeat-until'; classical Pascal lacks a 'break' keyword.
- C language: defines 'break' for loops and switch.
Concept / Approach:
We match the exact keyword and semantics. 'break' in C exits the nearest enclosing loop or switch. Other languages may have similar capabilities but different keywords or idioms (e.g., Fortran’s EXIT appears in later standards, not Fortran 77).
Step-by-Step Solution:
Check each language's standard keywords.Fortran 77: no 'break'; structured exits evolved later.Pascal (classic): no 'break'; alternatives exist.C: includes 'break' explicitly for loop/switch control.Therefore, the correct choice is C.Verification / Alternative check:
C references (K&R) and modern C standards document 'break' clearly, including behavior in nested structures.
Why Other Options Are Wrong:
- Fortran 77 and Pascal: different control constructs; lack the exact 'break' keyword in classic forms.
- none of the above/COBOL: do not match the described C keyword and semantics.
Common Pitfalls:
Assuming modern Fortran's EXIT or Pascal dialect extensions equate to classic 'break' keyword; the question targets the standard historic keyword usage.
Final Answer:
C