59 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-06-30 12:50:59 +02:00
include::../description.adoc[]
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:50:59 +02:00
----
for (var i = 1; i != 10; i += 2) // Noncompliant. Infinite; i goes from 9 straight to 11.
{
//...
}
2020-06-30 12:50:59 +02:00
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:50:59 +02:00
----
for (var i = 1; i <= 10; i += 2) // Compliant
{
//...
}
2020-06-30 12:50:59 +02:00
----
== Exceptions
Equality operators are ignored if the loop counter is not modified within the body of the loop and either:
2020-06-30 12:50:59 +02:00
* starts below the ending value and is incremented by 1 on each iteration.
* starts above the ending value and is decremented by 1 on each iteration.
2021-01-27 13:42:22 +01:00
Equality operators are also ignored when the test is against ``++null++``.
[source,javascript]
2020-06-30 12:50:59 +02:00
----
for (var i = 0; arr[i] != null; i++) {
// ...
}
for (var i = 0; (item = arr[i]) != null; i++) {
// ...
}
----
include::../see.adoc[]
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[]