Flip-flop (programming)

The following Ruby code prints the numbers 4 through 6: The first instance of ".." is the range operator, which produces the enumeration of integers 1 through 10.

These concurrent accesses to the state of the flip-flop operator can lead to undefined behavior, or at least surprising results, depending on the programming language.

For example, in Perl each flip-flop operator has its own state, shared among all the threads,[4] the other programming languages do the same.

To work around this limitation, the flip-flop operator would have to be modeled as an abstract data type, parameterized with: This flip-flop data type would provide a function that queries and updates its state at the same time.

Due to this inherent complexity, only few programming languages have adopted the flip-flop operator.