I want to create a command that changes its output the second time it gets called. For example, I want it to yield 1 the first time it's called, and 2 the second time:

```
\newcommand\mycommand { do stuff }
\mycommand % yields 1
\mycommand % yields 2

```

My idea was to define a global variable, something like `\hasbeencalled`, and globally redefine that variable if the command has been called. Something like:

```
\def\hasbeencalled{0}
\newcommand\mycommand[1] {
    \ifnum\hasbeencalled=0
        1
        \global\def\hasbeencalled{1}
    \else
         2
    \fi
}

```

But this doesn't work. Somehow the global redefinition happens retroactively and changes it so that I get the output

```
\mycommand % yields 2
\mycommand % yields 2

```

But if I take away the `\global`, then I get 

```
\mycommand % yields 1
\mycommand % yields 1

```

What can I do?