<p>Note that if one of the commands to execute is <a class="reference internal" href="quit.html"><span class="doc">quit</span></a>, as in
the first example above, then executing the command will cause LAMMPS
to halt.</p>
<p>Note that by jumping to a label in the same input script, the if
command can be used to break out of a loop. See the <a class="reference internal" href="variable.html"><span class="doc">variable delete</span></a> command for info on how to delete the associated
loop variable, so that it can be re-used later in the input script.</p>
<p>Here is an example of a loop which checks every 1000 steps if the
system temperature has reached a certain value, and if so, breaks out
of the loop to finish the run. Note that any variable could be
checked, so long as it is current on the timestep when the run
completes. As explained on the <a class="reference internal" href="variable.html"><span class="doc">variable</span></a> doc page,
this can be insured by includig the variable in thermodynamic output.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>A == B, A != B, A < B, A <= B, A > B, A >= B, A && B, A || B, !A
</pre></div>
</div>
<p>Each A and B is a number or string or a variable reference like $a or
${abc}, or A or B can be another Boolean expression.</p>
<p>If a variable is used it can produce a number when evaluated, like an
<a class="reference internal" href="variable.html"><span class="doc">equal-style variable</span></a>. Or it can produce a string,
like an <a class="reference internal" href="variable.html"><span class="doc">index-style variable</span></a>. For an individual
Boolean operator, A and B must both be numbers or must both be
strings. You cannot compare a number to a string.</p>
<p>Expressions are evaluated left to right and have the usual C-style
precedence: the unary logical NOT operator ”!” has the highest
precedence, the 4 relational operators “<”, “<=”, “>”, and “>=” are
next; the two remaining relational operators “==” and ”!=” are next;
then the logical AND operator “&&”; and finally the logical OR
operator “||” has the lowest precedence. Parenthesis can be used to
group one or more portions of an expression and/or enforce a different
order of evaluation than what would occur with the default precedence.</p>
<p>When the 6 relational operators (first 6 in list above) compare 2
numbers, they return either a 1.0 or 0.0 depending on whether the
relationship between A and B is TRUE or FALSE. When the 6 relational
operators compare 2 strings, they also return a 1.0 or 0.0 for TRUE or
FALSE, but the comparison is done by the C function strcmp().</p>
<p>When the 3 logical operators (last 3 in list above) compare 2 numbers,
they also return either a 1.0 or 0.0 depending on whether the
relationship between A and B is TRUE or FALSE (or just A). The
logical AND operator will return 1.0 if both its arguments are
non-zero, else it returns 0.0. The logical OR operator will return
1.0 if either of its arguments is non-zero, else it returns 0.0. The
logical NOT operator returns 1.0 if its argument is 0.0, else it
returns 0.0. The 3 logical operators can only be used to operate on
numbers, not on strings.</p>
<p>The overall Boolean expression produces a TRUE result if the result is
non-zero. If the result is zero, the expression result is FALSE.</p>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.