Limit Jump Statements (CONTINUE, EXIT) per Loop
WarningMetrics & Complexity Limits#EC MAX_LOOP_JUMPSRemote Enabled
Overview
Limit jump statements (CONTINUE/EXIT) per loop.
ATC Finding Message:
Loop has too many jump statements (CONTINUE/EXIT); simplify loop control flow
Rationale
Loops containing too many jump statements (CONTINUE, EXIT) have convoluted control flow that makes loop invariants difficult to reason about and maintain. Restructure the loop body using helper methods or simplified boolean conditions.
Non-Compliant
abap
LOOP AT lt_items INTO ls_item.
IF cond1. CONTINUE. ENDIF.
IF cond2. EXIT. ENDIF.
IF cond3. CONTINUE. ENDIF.
ENDLOOP.Compliant
abap
LOOP AT lt_items INTO ls_item WHERE ...
process_item( ls_item ).
ENDLOOP.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
MAX_LOOP_JUMPS | Integer | 2 | Maximum number of jump statements (CONTINUE/EXIT) allowed per loop (default: 2) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC MAX_LOOP_JUMPS
" SAP CI_ prefix format:
... "#EC CI_MAX_LOOP_JUMPSRelated Rules
- Avoid CHECK Statements —
#EC NO_CHECK_IN_LOOP - Disallow Nested LOOP AT Statements Without FROM or GROUP BY —
#EC NO_NESTED_LOOP - Limit Cyclomatic Complexity (McCabe Complexity Metric) —
#EC MAX_CYCLO_COMP
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_LOOP_JUMPS - Implementation File: zcl_skylint_max_loop_jumps.clas.abap