## Nested If Commands |
Top Previous Next |

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)} |