Skip to content

Commit

Permalink
Deploying to gh-pages from @ 3301562 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianAmbrosini committed Dec 24, 2024
1 parent aa6c577 commit 47ee6fe
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
75 changes: 69 additions & 6 deletions rules/S1264/csharp-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,86 @@ <h2 id="_description">Description</h2>
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When only the condition expression is defined in a <code>for</code> loop, and the initialization and increment expressions are missing, a <code>while</code> loop should be used instead to increase readability.</p>
<p>Using a <code>for</code> loop without its typical structure (initialization, condition, increment) can be confusing. In those cases, it is better to use a <code>while</code> loop as it is more readable.</p>
</div>
<div class="paragraph">
<p>The initializer section should contain a variable declaration to be considered as a valid initialization.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_how_to_fix_it">How to fix it</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Replace the <code>for</code> loop with a <code>while</code> loop.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
<h3 id="_code_example">Code example</h3>
<div class="sect3">
<h4 id="_noncompliant_code_example">Noncompliant code example</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-text" data-lang="text">for (;condition;) { /*...*/ }</code></pre>
<pre class="highlight"><code class="language-csharp" data-lang="csharp">for (;condition;) // Noncompliant; both the initializer and increment sections are missing
{
// Do something
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="sect3">
<h4 id="_compliant_solution">Compliant solution</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-text" data-lang="text">while (condition) { /*...*/ }</code></pre>
<pre class="highlight"><code class="language-csharp" data-lang="csharp">while (condition)
{
// Do something
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_noncompliant_code_example_2">Noncompliant code example</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-csharp" data-lang="csharp">int i;

for (i = 0; i &lt; 10;) // Noncompliant; the initializer section should contain a variable declaration
{
// Do something
i++;
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_compliant_solution_2">Compliant solution</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-csharp" data-lang="csharp">int i = 0;

while (i &lt; 10)
{
// Do something
i++;
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p>Microsoft Learn - <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/iteration-statements#the-for-statement">The <code>for</code> statement</a></p>
</li>
</ul>
</div>
<hr>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion rules/rule-index.json

Large diffs are not rendered by default.

0 comments on commit 47ee6fe

Please sign in to comment.