//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010, 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available
// under the terms of the MIT License which is available at
// https://opensource.org/licenses/MIT
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////

include::../_part_attributes.asciidoc[]

:leveloffset: -2

[[lang-tut-data-chapter-discvar-change]]
== Discrete variable value changes

indexterm:[discrete variable,value change]
Discrete variables can only change value by explicitly assigning them a new value in the `do` part of an edge.
If an edge does not assign a value to a discrete variable, that variable keeps its current value.
Consider the following CIF specification:

[source, cif]
----
automaton lamp:
  event turn_on, turn_off;

  disc int count = 0;

  location off:
    initial;
    edge turn_on  do count := count + 1 goto on;

  location on:
    edge turn_off                       goto off;
end
----

This is the same `lamp` automaton as used in the lesson on <<lang-tut-basics-chapter-automata,automata>>, but with a `count` variable added.
This variable is used to count the number of times that the lamp has been turned on.
The edge for the `turn_on` event increments the value of the variable by one, each time the lamp is turned on.

The edge for the `turn_off` event does not assign a value to a variable, so variable `count` keeps its value when the lamp is turned off.

The state space of this specification is:

image::{lang-tut-imgsdir}/data/discvar_change_state_space.png[]

The states are labeled with the name of the current location of automaton `lamp` and the current value of variable `count`.
