64 lines
1.1 KiB
Plaintext
64 lines
1.1 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)
|
|
|
|
include::message.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|