touque.ca > Education Commons > Programming: Concepts > Operators > Input

Concepts

Operators

Turing has arithmetic, string, relational, boolean, and assignment operators. The most commonly used operators are briefly described below.

Arithmetic operators

The unary arithmetic operators are:

The binary arithmetic operators are:

Sample code

% Declaration section
const BOX_CAPACITY := 12

var numberOfBoxes : int
var numberOfDoughnuts : int
var remainder : int

% Input section
put "How many doughnuts? " ..
get numberOfDoughnuts

% Processing section
numberOfBoxes := numberOfDoughnuts div BOX_CAPACITY
remainder := numberOfDoughnuts mod BOX_CAPACITY

% Output section
put "For ", numberOfDoughnuts, " doughnuts, you will need ",
   numberOfBoxes, " box(es)", skip, "-- and you'll have ",
   remainder, " left over!"

Relational operators

The binary relational operators are:

String operator

The binary string operator is + (concatenation).

Boolean operators

The unary boolean operator is not.

The binary boolean operators are or and and.

Assignment operator

The assignment operator is := and is pronounced “is assigned the value” or “gets.” For example:

Operator precedence

Arithmetic operations are performed according to conventional rules of precedence.

Operations which share a precedence level are executed in order from left to right. Here are the most common operations in descending order of precedence:

  1. **
  2. +, - (positive, negative)
  3. *, /, div, mod
  4. +, -
  5. <, <=, =, not=, >, >=
  6. not
  7. and
  8. or

touque.ca > Education Commons > Programming: Concepts > Operators > Input