in the first example, "ani" will count from 0 to infinite. (PRINT ani,0,0)
Usually you want an animation from 0...5 (e.g.), then write:
ani = MOD(ani + 1, 6) // will make ani from 0 to 5
if you have a ping-pong (0,1,2,3,2,1,...) animation, do this:
GLOBAL pingpong[]
DIMDATA pingpong[], 0,1,2,3,2,1
...
ani=ani+1
showani = pingpong[MOD(ani, LEN(pingpong[]) )]
This might seem a bit complicated in the first. Make sure you know what the MOD command does and then try to understand what I did.