Skip to content

Basics: Operators and Assignment

Bruce Long edited this page Jan 23, 2020 · 1 revision

Assignment

The CodeDog syntax for assigning a value to a variable is an arrow pointing left, in the direction the value is being assigned.

name <- "Matt"     // assign the value of "Matt" to name

The exception to the "<-" assignment is when assigning values to tags. Tags use "=" as an assignment operator.

description = 'Built in routines for Java'

Basic Arithmetic

12 + 3      // addition, evaluates to 15
11 - 4      // subtraction, evaluates to 7
2 * 6       // multiplication, evaluates to 12
4 / 2       // division, evaluates to 2

Equality

myInt == 5        // test for equality, this evaluates to true if myInt is 5
counter != 10       // test for equality, this evaluates to true if counter is not 10
ourObj1 === ourObj2   // test for pointer equality, this evaluates to true if both point to the same object

There are also the standard <, <=, > and >= operators for comparison.

Compound Assignments

Compound assignments can be made by inserting an operator in the middle of an assignment operator. For example, inserting the sum operator between the leading "<" and the closing "-" of a standard assignment operator, "<+-".

counter <+- 1      // shorthand for counter <- counter + 1
counter <-- 1      // shorthand for counter <- counter - 1
multiplier <*- 2   // shorthand for multiplier <- multiplier * 2
multiplier </- 2   // shorthand for multiplier <- multiplier / 2

In CodeDog, operator precedence is the same as in C++ and most C-like languages.

Clone this wiki locally