Avoid Loops That Execute At Most Once
WarningAnti-Patterns & Bad Practices#EC NO_SINGLE_ITERRemote Enabled
Overview
Avoid Loops That Execute At Most Once.
ATC Finding Message:
Loop contains an unconditional EXIT or RETURN and executes at most once
Rationale
A loop statement (LOOP, WHILE, or DO) containing an unconditional EXIT or RETURN at its top nesting level will execute at most once. This usually indicates an algorithmic bug, a leftover prototyping construct, or the misuse of a loop instead of a conditional block or helper method.
Non-Compliant
abap
LOOP AT lt_items ASSIGNING <ls_item>.
process( <ls_item> ).
EXIT.
ENDLOOP.Compliant
abap
IF line_exists( lt_items[ 1 ] ).
process( lt_items[ 1 ] ).
ENDIF.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_SINGLE_ITER
" SAP CI_ prefix format:
... "#EC CI_NO_SINGLE_ITERRelated Rules
- Avoid Dead Code with Constant Conditions —
#EC NO_DEAD_CODE - Avoid Dead / Unreachable Code —
#EC NO_UNREACHABLE - Prefer Early Return to Reduce Nesting (Guard Clauses) —
#EC PREF_GUARD_METHOD
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_SINGLE_ITER - Implementation File: zcl_skylint_no_single_iter.clas.abap