Table of Contents

Language - Assignment

About

An assignment is an expression that gives a value to a variable.

An assignment is not a statement but an expression.
The assignment is generally contained in one statement but not always, you may have several assignment expression in one statement.

Type and syntax

Implicit

Simple form

In its simplest form, an assignment statement has a variable on the left of the = sign and an expression on the right. This ordered form, and similar variations, is quite prevalent in modern programming languages.

variableName = value
value -> variableName
// or
value <- variableName

Generally in a language syntax,

Tuple

A tuple assignment allows several variables to be assigned at once.

Example: x becomes y and vice versa.

x, y = y, x

Operator (Compound)

An assignment operator (also known as Compound operator) is a short cut language structure that combine a math operation with assignment,

Example:

x = x * scale

can be rewritten as

x *= scale

The same is true for all:

Example of compound operator:

Explicit

Assignment statements are an explicit form of assignment, but there are many places in a program where an assignment occurs implicitly:

Go Example:

medals := []string{" gold", "silver", "bronze"}

implicitly assigns each element, as if it had been written like this:

medals[0] = "gold" 
medals[1] = "silver" 
medals[2] = "bronze"

Documentation / Reference