rspec/rules/S2190/java/rule.adoc
Gregory Paidis 2aa6cde667
Modify rule S2190: LaYC format (#1962)
Also remove unused languages.

---------

Co-authored-by: vilchik.elena <elena.vilchik@sonarsource.com>
2023-06-16 12:23:50 +02:00

41 lines
1.0 KiB
Plaintext

== Why is this an issue?
Recursion is a method of solving a computational problem where a method calls itself with smaller instances of the same input. This can happen when a method invokes itself or when a pair of methods invoke each other. It can be a useful tool, but unless the method includes a provision to break out of the recursion and ``++return++``, the recursion will continue until the stack overflows and the program crashes.
=== Noncompliant code example
[source,java]
----
int myPow(int num, int exponent) {
num = num * myPow(num, exponent - 1); // Noncompliant
return num; // this is never reached
}
----
=== Compliant solution
[source,java]
----
int myPow(int num, int exponent) {
if(exponent > 1) {
num = num * myPow(num, exponent - 1);
}
return num;
}
----
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[]