## Basic Usage

The new If command in the inline calculator allows you to create extremely complicated expressions.

The If command has the following format

**if(condition to be satisfied, value if true, value if false)**

For example, an if statement might look like this

**{if($n>0,100,-20)}**

When this command is run, the inline calculator will look at the value of the $n parameter. If the value is greater than 0, this statement will be replaced by 100. If the value is less than or equal to 0, the statement will be replaced by -20.

If commands will often include multiple parameters.

**{if($n>0,$p,$q)}**

With this command the inline calculator will return the value of either $p or $q, depending on the value of $n.

## Conditions

A condition is a Boolean statement that returns true or false. Conditions often include inequalities:

- $s<4
- $n>=6
- $q=9
- $t<>7 ($t is not equal to 7)

These are fairly simple conditions. You can combine these using the And, Or and Not commands as well as some of the more specialized Boolean commands to produce extremely complicated conditions.

## Numbers Or Text?

You can use the inline calculator to insert numbers or text into your equation. If you want to insert text into your equation, you must wrap the text in quotes.

For example:

**{if($d=0,”Cannot divide by zero”,$n/$d)}**

This command will look at the value of $d. If the value is 0, the inline calculator will return the text *Cannot divide by zero*. If $d is not zero, the calculator will divide $n by $d and return the result.

## Nested If Commands

If commands can be nested.

**{if($n=0,”n is zero”,if($n<0,”n is negative”,”n is positive”))}**

This command might take a little decoding…

If $n is zero, the command will return n is zero. If $n is not zero, the calculator will return the second result – which in this case is another if command. The calculator will execute the nested if command and return the appropriate response. There are no technical limits to the amount of nesting but the expressions can quickly become unwieldy. Often a better way to nest if commands is to assign commands to parameters. For example, if you assigned

**$p=if($n<0,”n is negative”,”n is positive”)**

You could then write the nested if command as

**{if($n=0,”n is zero”,$p)}**

## Boolean Conditions

We have added a number of commands to help you write Boolean conditions. Details can be found in the online documentation.

- And
- Or
- Xor
- Nor
- Not
- IsEven
- IsOdd
- IsInteger
- IsComposite
- IsPrime
- IsFactor
- IsNatural
- IsCube
- IsSquare