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:
+
(positive), and-
(negative).
The binary arithmetic operators are:
+
(addition),-
(subtraction),*
(multiplication),/
(division),div
(integer division), andmod
(modulo, the remainder of integer division).**
(exponentiation).
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:
<
(less than),<=
(less than or equal to),=
(equal to),not=
(not equal to),>
(greater than), and>=
(greater than or equal to).
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:
- “BOX_CAPACITY is assigned the value 12” or
- “BOX_CAPACITY gets 12.”
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:
**
+
,-
(positive, negative)*
,/
,div
,mod
+
,-
<
,<=
,=
,not=
,>
,>=
not
and
or
touque.ca > Education Commons > Programming: Concepts > Operators > Input
© 2007–2012 Hersch, Bear & Company Limited. All rights reserved. “touque.ca,” “Canada’s Thinking Cap,” “Grammar Authority,” and “grammarauthority.com,” are trademarks of Hersch, Bear & Company Limited. All other trademarks and copyrights are the property of their respective owners. | Privacy Policy | Licence to Copy | How to cite | Contact us