The problem
Animate returns a Manipulate:
Animate[var++, {n, 0, 9, 1}] // InputForm
(*
Manipulate[
var++,
{{n, 1}, 0, 9, 1,
AppearanceElements -> {"ProgressSlider", "PlayPauseButton",
"FasterSlowerButtons", "DirectionButton"}},
ControlType -> Animator, AppearanceElements -> None,
DefaultBaseStyle -> "Animate", DefaultLabelStyle -> "AnimateLabel",
SynchronousUpdating -> True, ShrinkingDelay -> 10.]
*)
Manipulate in turn wraps its body var++ with Dynamic. Thus the displayed expression depends on var and the body will be updated whenever var changes value. Since evaluation leads to incrementing var each time, updating occurs as rapidly as possible. Another issue, which might or might not be important, is that an Animator updates its variable n according to a Clock. This is so that equal changes in n occur in equal times. It is not guaranteed to increment by 1 at each step, if the animation rate is relatively high.
Solutions
The desired behavior requires var to be incremented whenever n changes. One approach is to make the body depend on n but not on var. TrackedSymbols will help restrict dependency to explicitly listed symbols.
Potentially buggy solutions
The simplest approach is to add the expression n; to the body, and restrict the tracked symbols to n:
var = 0;
Animate[n; var++, {n, 0, 9, 1}, TrackedSymbols :> {n}]
This will behave in the desired way on most or all computer systems.
The problem is that n will be incremented at a constant rate no matter how long it takes n; var++ to execute and be redisplayed. It is possible for n to be increased by more than var. This can be observed in the following. The AnimationRate might need to be adjusted for a particular computer. On mine, the variables start to slip apart around a rate of 20 or 25 and constantly slip at a rate of 100.
var = 0;
Animate[var++; {Mod[n - var, 10], n, var}, {n, 0, 9, 1},
AnimationRate -> 100, TrackedSymbols :> {n}]
Synchronized, but might not always be updated by one
If the variables need to be synchronized, then the updating var at the same time as n is the way to go. This can be done with the second argument of Dynamic. Since Animate automatically sets up the control for n, I'll adapt the Manipulate code above to customize the Animator control.
var = 1;
Manipulate[
{Mod[var - n, 10], n, var},
{{n, var},
Animator[Dynamic[n, (var += # - n; n = #) &],
{0, 9, 1},
AppearanceElements -> {"ProgressSlider", "PlayPauseButton",
"FasterSlowerButtons", "DirectionButton"}] &},
AppearanceElements -> None, DefaultBaseStyle -> "Animate",
DefaultLabelStyle -> "AnimateLabel", SynchronousUpdating -> True,
ShrinkingDelay -> 10.]
Synchronized, updated by one
One can override the default update of n in the previous code to ensure that n and var are incremented by 1 each time. This breaks the synchronization with Clock and the direction button of the Animator. (One probably ought to omit "DirectionButton" from AppearanceElements, but I'll leave it in so one can try it.)
var = 1;
Manipulate[
{Mod[var - n, 10], n, var},
{{n, var},
Animator[Dynamic[n, (var++; n = Mod[n + 1, 10]) &],
{0, 9, 1},
AnimationRate -> 100,
AppearanceElements -> {"ProgressSlider", "PlayPauseButton",
"FasterSlowerButtons", "DirectionButton"}] &},
AppearanceElements -> None, DefaultBaseStyle -> "Animate",
DefaultLabelStyle -> "AnimateLabel", SynchronousUpdating -> True,
ShrinkingDelay -> 10.]
var, i.e.,var = 1; Animate[var++, {n, 0, 10, 1}]works as exptected. Or, if you want to restvarin every cycle you can usevar = 1; Animate[Mod[var++, 10, 1], {n, 0, 10, 1}]. Also look at Clock, e.g.Dynamic@Clock[{0, 10, 1}]– kglr Aug 24 '14 at 14:22var, or he wouldn't have observed the behavior that he observed. – C. E. Aug 24 '14 at 14:47