Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1264

A "while" loop should be used instead of a "for" loop

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Replace this "for" loop with a "while" loop.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Flex
    • Covered Languages:
      C#, C, C++, Java, JavaScript, Objective-C, PHP, TypeScript
    • Irrelevant for Languages:
      ABAP, Cobol, Go, HTML, PL/I, PL/SQL, Python, RPG, Swift, T-SQL, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • PMD:
      ForLoopShouldBeWhileLoop
    • TSLint:
      prefer-while

      Description

      When only the condition expression is defined in a for loop, and the initialization and increment expressions are missing, a while loop should be used instead to increase readability.

      Noncompliant Code Example

      for (;condition;) { /*...*/ }
      

      Compliant Solution

      while (condition) { /*...*/ }
      

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-3954 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-5520 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                freddy.mallet Freddy Mallet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: