Question: if I want to express something like [just a simple example]:

```
int a = 0;
for (int x = 0; x < n; x += 1)
    a = 1 - a;

```

what should I do in Haskell, *since it doesn't have variable concept?* (maybe wrong, see: [Does Haskell have variables?](https://stackoverflow.com/questions/993124/does-haskell-have-variables))

Answer: 
Often, repetition that you would perform with a loop in a procedural language is accomplished with [recursion](http://learnyouahaskell.com/recursion) in Haskell. In this case, you should think about what the result of the loop is. It appears to alternate between 0 and 1. There are several ways to do this in Haskell. One way is

```
alternatingList n = take n alternating0and1
alternating0and1 = 0 : alternating1and0
alternating1and0 = 1 : alternating0and1

```
Another option:

```
iterate (\a -> 1-a) 0 !! n
-- or even
iterate (1-) 0 !! n

```

The snippet `iterate (\a -> 1-a) 0` produces an infinite lazy list of all the values obtained starting from `0` and repeatedly applying the function `(\a -> 1-a)`. Then `!! n` takes the n-th element.

To be completely honest, in this case, I'd also look for a stricter definition of `iterate` which does not create so many lazy thunks.