# Can I use logical operators in calculations?

Yes, the calculations in AlisQI do support basic logic operators (and + or).
You can create simple if then else statements with the ? and : operators.

In fact, the calculation engine has many advanced features. Read the documentation on the advanced calculation engine to learn about all of its capabilities.

## Combine conditions

If you want to combine conditions with a logical AND use "and" or "&&" (ampersand).

```conditionA and conditionB
```

If you want to combine conditions with a logical OR use "or" or "||" (pipes).

```conditionA or conditionB
```

## If then else-notation

If (condition) then (A) else (B)

Can be defined as:

```condition ? A : B
```

## Example

Imagine a form to calculate the surface of an area (either a square or a circle).
We have the fields: {length}, {width} and {radius}.

Now you want the calculation to be smart enough to distinguish the area type, based on the inputted dimensions.

If the radius is specified, use:

```{radius}*pi^2
```

Otherwise, use:

```{length}*{width}
```

This can be combined in a single evaluation:

```{radius} ?  {radius}*pi^2 : {length}*{width}
```

## Reuse the condition as value (?: notation)

If you want to use the value of the condition in the then leg of your evaluation, simply use the ?: notation.

```condition ? condition : B
```

can be condensed to

```condition ?: B
```

## Logical and/or

Combine conditions with logical AND / OR operators.

AND operator (or &&)

if ConditionA and ConditionB then 1 else 0 can be defined as:

```ConditionA and ConditionB ? 1 : 0
```

OR operator (or ||)

if ConditionA or ConditionB then 1 else 0 can be defined as:

```ConditionA or ConditionB ? 1 : 0
```

Be aware that operators are case sensitive.

Still need help? Contact Us Contact Us