zcodescan.cobol.rules.NestedIfLimitRulee
Avoid nesting IF statements deeper than the specified number of levels.
categories:
- name: "Program Structure"
rules:
- id: "zcodescan.cobol.rules.NestedIfLimitRule"
name: "Avoid nesting IF statements deeper than the specified number of levels"
description: "Avoid nesting IF statements deeper than the specified number of levels"
severity: MEDIUM
software_quality: MAINTAINABILITY
cleancode_attribute: LOGICAL
parameters:
- name: "NestingLimit"
value: 2
description: |
IF statement contains an IF statement as one of its possible branches, the IF statements are said to be nested. Theoretically, there is no limit to the depth of nested IF statements.
However, use nested IF statements sparingly. The logic can be difficult to follow, although explicit scope terminators and indentation can help.
If a program has to test a variable for more than two values.
IF USER-LOGGED-IN = 'Y'
IF USER-ROLE = 'ADMIN'
IF ACCESS-LEVEL > 3
IF FEATURE-ENABLED = 'Y'
DISPLAY 'Access granted to admin feature'.
END-IF
END-IF
END-IF
END-IF