We want to be able to compare variables to one another; say, to find out if x is greater than y. In IDL, you use relational operators to do this. For example, "x gt y" tests if x is greater than y, producing "true" or "false" as a result. Other operators are "lt" for less than, "eq" for equal, "ne" for not equal, "le" for less than or equal, and "ge" for greater than or equal. You use these operators in exactly the same way that you use "*" in "x*y" producing a multiplication result.
We can combine tests by using "and" and "or" operators. "a and b" is true if both a and b are true, false otherwise. "a or b" is false only if a and b are both false. You can also use "not a" which is true if a is false and vice versa.
On its own, a true or false statement is not of much use. These come in handy in conditional statements, of which "if" is the most commonly used. You tell the computer to " if some condition holds, then do some task". For example:

Often we want to say "if some condition holds, then do some task, else (if the condition is false) do some other task instead."

If the statement becomes too long for one line, we can break it by using the continuation character, "$", which tells IDL that the statement continues on the next line. Here's how you'd do that in an IDL procedure:

Using too many "$" continuations is awkward. Plus you may want to execute more than one statement as part of the if and else tasks. So we use the "begin" and "endif/endelse" statements to tell IDL that we are going to spread out the tasks over multiple statements. Proper indentation really helps readability in such cases!

A more complex example, where you have another conditional in the else part.

And here is an example where you have multiple statements in the if and else tasks.

| Taner Edis | Home |
| Last modified: October 25, 2006 |   |