Expressions and Operators

An Expression is a statement that has a value. For example:a = 1

y > 4

tab$(3) = "Hello"

tab$(0) <> ""

There are four kinds of expressions: arithmetic, character (string), relational, logical.

Arithmetic

An arithmetic expression produces an integer value. The following table shows the available arithmetic operators:

Arithmetic operator | Representing |

+ | Addition |

- | Subtraction |

* | Multiplication |

/ | Division (integer division) |

mod | Modulus |

() | Parenthesis |

- | Unary minus |

a=5-3 'a contains 2

a=3*5 'a contains 15

a=11/2 'a contains 5

a=11 mod 2 'a contains 1

a=(3+2*3)*2 ' a contains 18

a=1

b=-a 'a contains -1

String

A string expression produces a result of data type string. The only string operator is +, representing concatenation.

b$=" "

c$="WinTask"

d$=a$+b$+c$ 'd$ contains "Hello WinTask"

Relational

A relational expression produces a result of type logicial. It can be an arithmetic relational expression or a string relational expression. The following table shows the available relational operators:

Relational operator | Representing |

< | Less than |

<= | Less than or equal to |

= | Equal to |

<> | Not equal to |

> | Greater than |

>= | Greater than or equal to |

The string expressions are evaluated one character at a time from left to right. The comparison of two strings uses the order specified by the ASCII collating sequence. If the strings are of unequal length, the shorter is extended on the right with blanks.

**Examples
**If a < b then...

If i < 10 then...

If a$ = " " then...

If a$ < "Hello" then...

Logical

A logicial expression produces a result of type logical. The following table shows the available logical operators:

Logicial operator | Representing |

AND | Logical conjunction |

OR | Logical inclusive disjunction |

NOT | Logicial negation |

If (a=b) OR NOT (c=d) then ...' TRUE if a=b or c not equal to d

Operator Precedence

Arithmetic operators are evaluated first, then relational operators, then logical operators.

For arithmetic operators, operator precedence is:

- Unary (-)
- Multiplication and division (*,/)
- Modulus (mod)
- Addition and subtraction (+, -)

For logicial operators, operator precedence is:

- Negation (NOT( ))
- Logical AND (AND)
- Logical OR (OR)

The relational operators have the same level of precedence. They are evaluated from left to right.

You can use parenthesis to force the order of evaluation.

See also