if
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | if [2007/05/31 03:59] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ======Synopsis: | ||
| + | __if__ (< | ||
| + | __if__ (< | ||
| + | __if__ (< | ||
| + | __if__ (< | ||
| + | __if__ (< | ||
| + | |||
| + | ======Description: | ||
| + | __IF__ is the general purpose control statement for testing the truth/false | ||
| + | value of a given condition. | ||
| + | some action; if false, some alternate action. | ||
| + | necessarily need to be a numeric comparison. | ||
| + | return value is evaluated for truth or falsity, or compared against some | ||
| + | other value (which might also be a function return value). | ||
| + | are generally of the following forms: | ||
| + | |||
| + | |( exp ) |tests for existence of exp (usually a variable) | ||
| + | |( !exp ) |tests for non-existence of exp | | ||
| + | |( exp1 == exp2 ) |tests whether exp1 equals exp2 | | ||
| + | |( exp1 != exp2 ) |tests whether exp1 does not equal exp2 | | ||
| + | |( exp1 && exp2 ) |tests for existence of exp1 and exp2 | | ||
| + | |( exp1 %%||%% exp2 ) |tests for existence of exp1 or exp2 or both | | ||
| + | |( exp1 %%^^%% exp2 ) |tests for existence of exp1 or exp2, not both | | ||
| + | |( exp1 < exp2 ) |tests whether exp1 is less than exp2 | | ||
| + | |( exp1 > exp2 ) |tests whether exp1 is more than exp2 | | ||
| + | |( exp1 <= exp2 ) |tests whether exp1 is less than or equal to exp2 | | ||
| + | |( exp1 >= exp2 ) |tests whether exp1 is more than or equal to exp2 | | ||
| + | |||
| + | The " | ||
| + | if the " | ||
| + | not required either. | ||
| + | were within a ${} construct, such that | ||
| + | |||
| + | if ( blah ) ... | ||
| + | |||
| + | would expand " | ||
| + | can also be placed inside the expression parser, such that | ||
| + | |||
| + | if ( [$blah] ) ... | ||
| + | |||
| + | is equivalent to the previous statement (though it isn't as efficient). | ||
| + | Both forms may be combined in the same expression. | ||
| + | as constants, so in order to expand numeric expandos, such as $0, you | ||
| + | must use the expression parser, as above. | ||
| + | through the expression parser (otherwise they are interpreted as | ||
| + | variables), and are compared case-insensitively. | ||
| + | |||
| + | As in C, assignment operators may be used inside __IF__ statements. | ||
| + | generally not recommended, | ||
| + | confusing, but there are times when it can prove to be useful. | ||
| + | following: | ||
| + | |||
| + | if ( foo = 3 > bar ) ... | ||
| + | |||
| + | would first set the value of $foo to 3, and then compare it with $bar. | ||
| + | Note that the @ operator is not needed (and in fact is not even allowed). | ||
| + | Gratuitous use of parenthesis is recommended with this notation. | ||
| + | |||
| + | Finally, as with other ircII-EPIC control statements, the curly braces | ||
| + | may be placed anywhere. | ||
| + | |||
| + | ======Examples: | ||
| + | The following two statements are functionally equivalent: | ||
| + | if ( foo == bar ) echo foo and bar are the same | ||
| + | if ( foo == bar ) { | ||
| + | echo foo and bar are the same | ||
| + | } | ||
| + | |||
| + | These are also equivalent: | ||
| + | if ( !foo ) ... | ||
| + | unless ( foo ) ... | ||
| + | |||
| + | Braces are required for a multi-line then portion: | ||
| + | if ( foo == bar ) { | ||
| + | echo foo and bar are the same | ||
| + | echo that's so cool! | ||
| + | } | ||
| + | |||
| + | Like other control statements, IFs may be embedded: | ||
| + | if ( foo ) { | ||
| + | if ( bar ) { | ||
| + | echo foo and bar are both non-empty! | ||
| + | echo that's so cool! | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Function return values can be evaluated too: | ||
| + | if ( rmatch(foobar *blah* *bar) ) { | ||
| + | echo it matched | ||
| + | } | ||
| + | |||
| + | ======Aliases: | ||
| + | [[UNLESS]] is the exact opposite of __IF__. | ||
| + | the negation operator (!) to the entire __IF__ condition. | ||
| + | |||
| + | ======Other Notes: | ||
| + | The " | ||
| + | of the negation operator and [[UNLESS]] obsolete this practice, however. | ||
| + | |||
if.txt · Last modified: 2007/05/31 03:59 by 127.0.0.1
