IF Expression
IF selects one of two branches from a condition.
Syntax
If the true branch is omitted or empty, it defaults to 1. If the false branch is omitted or empty, it defaults to 0.
Condition evaluation
ACE resolves the condition first. It then tries to convert the resolved condition with std::stoi:
- if conversion succeeds and the resulting integer is
0, ACE selects the false branch; - if conversion succeeds and the resulting integer is non-zero, ACE selects the true branch;
- if integer conversion throws, only the exact string
0selects the false branch; any other string selects the true branch.
For normal boolean logic, use conditions that resolve to 0 or 1.
Examples
These basic forms are already covered by ACE's expression tests:
Lazy evaluation
IF is evaluated lazily. ACE resolves the condition first and then resolves only the selected branch. Expressions in the other branch are not evaluated.
This is especially important with command expressions:
Only the CMD in the selected branch is resolved and passed to the ACE resolver. The CMD in the unselected branch is not evaluated.