== Why is this an issue?

Using a `for` loop without its typical structure (initialization, condition, increment) can be confusing. In those cases, it is better to use a `while` loop as it is more readable.

The initializer section should contain a variable declaration to be considered as a valid initialization.

== How to fix it

Replace the `for` loop with a `while` loop.

=== Code example

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
for (;condition;) // Noncompliant; both the initializer and increment sections are missing
{
    // Do something
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
while (condition)
{
    // Do something
}
----

==== Noncompliant code example

[source,csharp,diff-id=2,diff-type=noncompliant]
----
int i;

for (i = 0; i < 10;) // Noncompliant; the initializer section should contain a variable declaration
{
    // Do something
    i++;
}
----

==== Compliant solution

[source,csharp,diff-id=2,diff-type=compliant]
----
int i = 0;

while (i < 10)
{
    // Do something
    i++;
}
----

== Resources

=== Documentation

* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/iteration-statements#the-for-statement[The `for` statement]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
