Answer the question
In order to leave comments, you need to log in
Why can't loops be used in functional programming?
When declaring a loop, we assign a value (let i = 0) and this value cannot be changed from outside.
Each time this function is called with a loop, i in this case will always be 0 on the first iteration.
And as a second option, we can pass an argument to the function that will set the value of the counter i.
So why can't loops be used in functional programming?
Addendum:
My question can be rephrased as follows: does it make rational sense to follow these rules absolutely and without exceptions?
Here is an example:
const i = 666;
function count (a,b) {
for (let i = 0; i < 10; i++) {
console.log((a+b)*i);
}
}
count(1,2);
console.log(i);
Answer the question
In order to leave comments, you need to log in
Functional programming assumes that any variable is assigned a value exactly once and cannot be assigned. changed. This condition means the impossibility of completing the cycle, and any: for, while, repeat-until.
Those. the problem is not with the initial value assignment, but with subsequent type changesi++
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question