Template:Xifnoteq/doc

The Template:Xifnoteq provides a quick, extended if-not-equal function, as a reverse check, beyond the parser function #ifeq.
 * Usage:
 * &rarr;

Parameters:
 * {1} - the 1st value to compare
 * {2} - the 2nd value to compare to 1st
 * {3} - result when not equal (as then-part of if)
 * {4} - result when equal (as else-part of if)

For small results, the processing speed will be very similar to #ifeq (see below: Performance and resources).

Examples
Some examples help to show the extended capability to handle cases such as a leading colon or leading-pound sign which might trigger indented numbering when used in #ifeq:
 * &rarr;


 * "" &rarr; ""
 * "" &rarr; ""
 * &rarr;
 * &rarr;

Because a leading pound# (hash mark) can trigger auto-indentation as a numbered list, treats a leading "#" (or colon ":" or asterisk " " or semicolon ";") as being typical data, rather than indentation markup codes. As other problems arise with #ifeq, then this template can be modified to overcome those glitches and continue to work in a predictable manner.

The coding inside Template:Xifnoteq has been optimized to use only 2 levels of expansion nesting (see "m:Help:Expansion depth"), and runs very fast.

Limitations
The Template:Xifnoteq has the following limitations: it requires special coding for equal-sign "="; it performs numeric comparison unless {1} and {2} are not numbers.

As typical with #ifeq, the 2 values are compared numerically (where "2" equals "2.0") unless the values are not numbers:
 * &rarr;

The numeric comparison can be avoided by putting a letter such as "z" in front of both values to compare: {&#123;xifnoteq|z{&#123;{1}}}|z{&#123;{2}}}|...}} to force an alphanumeric comparison.

Because Template:Xifnoteq processes the then-clause and else-clause as template parameters, they cannot contain a simple equal-sign as in "x=x" so use either an unnamed parameter "x{&#123;{|=}&#125;}x" or "x{&#123;=&#125;}x" or set parameters by both number 3 and 4: "3=not =x" (then-clause) plus "4=x=x" (else-clause).


 * &rarr;
 * &rarr;
 * &rarr;

Note how the parser function #ifeq allows the simple equal-sign "x=x" whereas xifnoteq needs both "3=not =x" and "4=x=x" to allow an equal-sign in parameter 3. For those reasons, using an unnamed parameter "x{&#123;{|=}&#125;}x" is often the easiest method.

Performance and resources
The Template:Xifnoteq is designed to run very quickly, with minimal expansion nesting (as 2 levels) and format concise results similar to #ifeq. However, unlike #ifeq, both the then-clause and else-clause will be expanded before the comparison is made. Also, unlike #ifeq, the intermediate expansion sizes of both the then-clause and else-clause are both counted, and counted double, against the resource post-expand size (of 2,000 kb conditional text). If the then-cause and else-clause are roughly equal in size, the post-expand size would be 4x times that size. However, only the actual choice of then-clause or else-clause is formatted into the final page; the post-expand size is just an intermediate limit for the MediaWiki preprocessor.

During intermediate processing, Template:Xifnoteq requires the formatting of both the then-part and else-part, before choosing between the 2 sets of formatted results. In most cases, there is no significant speed delay because hundreds of templates can be processed very quickly before choosing between 2 if-else branches.

The method for allowing spaces in if-logic, in January 2011, used 2 nowiki-slash tags "&lt;nowiki/>" around the then-clause and else-clause: &rarr; " yes ".