0

sorry if I bother someone with this simple question, but I just can not get around all of this concepts in one for loop and can not understand how this code can be written in a more explicite manner

Code:

eval(`for(a=c=100n**n*20n,d=1n;a*=d;)c+=a/=d+++d`)

What I have so far:

let c=100n**n*20n
for(let a=100n**n*20n, d=1n; a*=d; ) {
    c+=a/=d+++d
}

How I understand it: We instantiate 2 variables(a and d) insider the for loop and incrementing a at each iteration with a = a * d. Question: How do I read the c variable update c+=a/=d+++d and until what condition this for loop will be executed ?

Thanks for any expiation on the topic! PS: it does not matter if your explanation will be using BigInts as in this example

Nichita
  • 1
  • 1
  • 1
  • See [What does this symbol mean in JavaScript?](https://stackoverflow.com/q/9549780/4642212) and the documentation on MDN about [expressions and operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) and [statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements). What do you mean by _“How do I read the c variable update”_? Are you asking what it means? Assignment expressions are evaluated right to left: `c += (a /= (d++ + d))`. See [AST Explorer](https://astexplorer.net/). `a *= d` results in `a * d`. How is `eval` relevant here? – Sebastian Simon Apr 02 '21 at 20:30
  • Thank you for the hint, I dont see a terminal condition for this loop, so can you see at which point will stop executing this loop ? – Nichita Apr 03 '21 at 08:32
  • The loop stops when `a * d` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). – Sebastian Simon Apr 03 '21 at 12:39

0 Answers0