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: 
There are a few options. First, you can rewrite the problem with naive recursion:

```
loop :: Int -> Int
loop n = loop' n 0
  where loop' 0 a = a
        loop' n a = loop' (n - 1) (1 - a)

```

Next, you can restate recursion as a fold:

```
loop :: Int -> Int
loop n = foldr (\a _ -> 1 - a) 0 [0..n]

```

Or you can use `State` to simulate a for loop:

```
import Control.Monad
import Control.Monad.State

loop :: Int -> Int
loop n = execState (forM_ [0..n] 
                      (\_ -> modify (\a -> 1 - a))) 0

```
In Haskell instead of using loops, you combine standard library functions and/or your own recursive function to achieve the desired effect.

In your example code you seem to be setting `a` to either 0 or 1 depending on whether or not `n` is even (in a rather confusing fashion if I'm honest). To achieve the same in Haskell, you'd write:

```
a =
  if even n
  then 0
  else 1

```