ligo/gitlab-pages/docs/language-basics/variables.md
2019-06-11 03:37:12 +02:00

1.1 KiB

id title
variables Variables

Defining a variable

Variables in LIGO can be defined in two ways - by using either the const or var keywords. const can be used both at global (top-level) and local scope (within functions/blocks), while var can be used for mutable values in the local scope.

Imutable variables using const

⚠️ Currently const values are mutable as well, however this is something that will change in the upcoming release. For the time being think of const as a semantical way to indicate developer intentions.

const four: int = 4;

Mutable variables using var

⚠️ var can't be used in the global scope

// won't work, use const for global values instead
var four: int = 4;

// value of `number` can be mutated within local scope
function addFour(var number: int): int is
  block { 
    number := number + 4;
  } with number;