
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
67 lines
1.2 KiB
Plaintext
67 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
int Pow(int num, int exponent) // Noncompliant; no condition under which pow isn't re-called
|
|
{
|
|
num = num * Pow(num, exponent-1);
|
|
return num; // this is never reached
|
|
}
|
|
|
|
void WhileLoop() // Noncompliant; no condition under which while loop would exit
|
|
{
|
|
while (true)
|
|
{
|
|
var line = Console.ReadLine();
|
|
Console.WriteLine(line);
|
|
}
|
|
}
|
|
|
|
void InternalRecursion(int i)
|
|
{
|
|
start:
|
|
goto end;
|
|
end:
|
|
goto start; // Noncompliant; there's no way to break out of this method
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
int Pow(int num, int exponent)
|
|
{
|
|
if (exponent > 1) // recursion now conditional and stop-able
|
|
{
|
|
num = num * Pow(num, exponent-1);
|
|
}
|
|
return num;
|
|
}
|
|
|
|
void WhileLoop()
|
|
{
|
|
string line;
|
|
while ((line = Console.ReadLine()) != null) // loop has clear exit condition
|
|
{
|
|
Console.WriteLine(line);
|
|
}
|
|
}
|
|
----
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add a way to break out of this \[[method|property|property accessor]'s recursion|method|property accessor].
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|