== Why is this an issue?

The assignment of a boolean variable inside the test of a control structure such as an ``++if++``, ``++while++`` or ``++for++`` loop is almost always a mistake and should be corrected to avoid unexpected program results. In fact, even if it was done on purpose, it should be re-examined. 


=== Noncompliant code example

[source,html]
----
boolean b = false;
if ( b = m.getTrue()) { ... } // Noncompliant

while (b = getTrue()) { ... } // Noncompliant; unintentionally infinite

for (int i = 0; i < 10 && b = getTrue(); i++) { ... } // Noncompliant
----


=== Compliant solution

[source,html]
----
boolean b = false;
if ( b = m.getTrue())
{
  System.out.println("How did we get here");
}
----



ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

=== duplicates: S1121

=== on 21 Oct 2014, 18:57:07 Nicolas Peru wrote:
Isn't that covered by this one \http://jira.sonarsource.com/browse/RSPEC-1121 ?

=== on 21 Oct 2014, 20:30:47 Ann Campbell wrote:
Uhm... you tell me [~nicolas.peru]. I did look at that one, but from the examples decided not.

=== on 22 Oct 2014, 07:08:39 Nicolas Peru wrote:
For me this is completely covered by RSPEC-1121 and as it also provides exception I would not bother with this one.

endif::env-github,rspecator-view[]
