Programming Operators and Precedence of Calculation
An operator is a mathematical symbol or term used to connect or compare two or more parts of a program or assign a value. The following shows Sesame-supported operators with usage examples:
+ |
Addition1Total = Amount + Sales Tax
|
- |
SubtractionDifference = GrandTotal = EstimatedTotal
|
* |
MultiplicationSales Tax = Amount = .072
|
/ |
DivisionCost = Amount / Quantity
|
= |
Equal toIf Priority = "A" Then ShipDate = OrderDate + 1
|
< |
Less thanIf ShipDate < OrderDate Then WriteLn("Whoops!")
|
> |
Greater thanIf (@Year(@Date)) - @Year(BirthDate)) > 16 Then Class = "Adult"
|
<= |
Less than or equal toIf BirthDate <= @D(1999/12/31) Then WriteLn("Child of the 20th Century (probably)")
|
>= |
Greater than or equal toIf Qty >= 1000 then Price = Price * .95
|
<> |
Not equal toIf State <> "PA" Then @Msg("No Sales Tax")
|
AND |
Both comparisons are trueIf ((@Yr(@Date) - @Yr(BirthDate)) < 17) AND (Gender = "M") Then @Msg("Now behave yourself, laddie")
|
OR |
Either comparison is trueIf (Total . 1000) OR (Status = "VIP") Then @Msg("Order must be shipped by " + @Str(OrderDate + 1))
|
NOT |
Reverses comparisonIf NOT @Error Then @Msg(It Worked!")
|
1Arithmetically sums values if they are of numeric data type, as assumed in first example (includes Integer, Double, Money, Boolean, Date, Time values). Otherwise, concatenates (combines) values as in second example. Typecasting functions can be used to convert between data types.
Precedence of Calculation in ProgrammingThe following show precedence (the order) of calculation from highest (calculated first) to lowest (calculated last) (operators on the same line have the same precedence – Sesame evaluates them from left to right as they appear in your program). As a matter of good practice, you should use parentheses to control precedence rather than depend on the following order.
- (...) Anything contained in parentheses
- * / Multiplication and division
- + - Addition and subtraction
- <, >, <=, >=, <> Lesser than, greater than, less than or equal to, greater than or equal to, not equal to
- NOT Reverses comparison’s values
- AND OR Both comparisons true, either comparison true