include::../summary.adoc[]

== Why is this an issue?

include::../rationale.adoc[]

include::../impact.adoc[]

== How to fix it

=== Code examples

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
public class ExampleController : Controller
{
    public IActionResult Compute(int data)
    {
        for (int i = 0; i < data; i++) // Noncompliant
        {
            Console.WriteLine("Hello");
        }

        Enumerable
            .Range(1, data) // Noncompliant
            .ToList()
            .ForEach(i => Console.WriteLine("World"));

        return Ok();
    }
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
public class ExampleController : Controller
{
    public static int MAX_BOUNDARY = 1337;
    public static int MIN_BOUNDARY = 1;

    public IActionResult Compute(int data)
    {
        
        if (MIN_BOUNDARY > data)
        {
            data = MIN_BOUNDARY;
        }
        else if (data > MAX_BOUNDARY)
        {
            data = MAX_BOUNDARY;
        }

        for (int i = 0; i < data; i++)
        {
            Console.WriteLine("Hello");
        }

        Enumerable
            .Range(1, data) // Noncompliant
            .ToList()
            .ForEach(i => Console.WriteLine("World"));

        return Ok();
    }
}
----

=== How does this work?

include::../common/fix/limits.adoc[]

== Resources

include::../common/resources/standards.adoc[]

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

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

include::../message.adoc[]

include::../highlighting.adoc[]

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