15 June, 2014 by Denise << functional-programming >>

For loops and functional programming

I feel like this was probably obvious to everyone except me, but I just realised that the functional programmer's aversion to the for loop is because it has side effects, i.e. in the following code:

for (int i = 0; i < 10; i++) {
    //do stuff
}

the value of i is modified each time the code loops, which is a side effect.