What is the output?
I saw this code snippet from a Tweet reply to Jake Archibald‘s tweet.
You don't even need generators / async to show this behavior. pic.twitter.com/CPRYWpXJjL— Kyle Ehrlich (@KyleDavidE) May 24, 2018
The answer is
For a detailed explanation, watch this YouTube video from Jake. In short, the value of
val is evaluated at the point the statement is encountered. In both the increment statements, the value of
val is 0 when they are being evaluated. This is why the values are never added summed up.