Ada Operators and Conditional Expressions
- Operators (highest precedence first):
- **, abs, not
- *, /, mod, rem
- +, - (unary)
- +, -, & (binary)
- =, /=, <, <=, >, >=
- and, or, xor
- Notes on the above:
- The above operators can be redefined by the user.
- Parentheses required in some situations (eg a and b or c)
- rem and mod differ for negative numbers
- & is string concatenation
- Other operator-like items:
- and then, or else (short circuit - only evaluate second operand if needed)
- if a and then b then -- b only evaluated if a is true
- if a or else b then -- b only evaluated if a is false
- in, not in (examples: if i in Natural, if i not in 1 .. 10 | 20 .. 30)
- Conditional Expressions:
- Evaluates to one of several values
- Two forms: if and case
- Examples:
-
x := (if a = b then 3 else 4);
-
put(case day of Mon|Wed|Fri => 2, Tu|Th => 1,
others => 0);
- Must be immediately surrounded by parentheses