
In some cases, the `rule.adoc` at root of a rule is never included anywhere and thus is dead code. It's a maintenance cost by itself, but also it misses opportunities to inline code that seems used by two documents when in fact only one document is actually rendered. And this missed opportunity, in turn, stops us from applying the correct language tag on the code samples.
58 lines
1.0 KiB
Plaintext
58 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
An infinite loop is one that will never end while the program is running, i.e., you have to kill the program to get out of the loop. Whether it is by meeting the loop's end condition or via a ``++break++``, every loop should have an end condition.
|
|
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,kotlin]
|
|
----
|
|
var j: Int
|
|
while (true) { // Noncompliant; end condition omitted
|
|
j++
|
|
}
|
|
|
|
var k: Int
|
|
val b = true
|
|
while (b) { // Noncompliant; b never written to in loop
|
|
k++
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,kotlin]
|
|
----
|
|
var j: Int = 0
|
|
while (true) { // reachable end condition added
|
|
j++
|
|
if (j == Int.MIN_VALUE) { // true at Integer.MAX_VALUE +1
|
|
break
|
|
}
|
|
}
|
|
|
|
var k: Int = 0
|
|
var b = true
|
|
while (b) {
|
|
k++
|
|
b = k < Int.MAX_VALUE
|
|
}
|
|
----
|
|
|
|
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[]
|