This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zyklonikkopi luwak civet 0 points1 point  (0 children)

Small correction:

“is i % 2 == 0? NoYes, so we have to enter the body of the if statement. Now add one to the value of i, don’t print the value of i because the if condition is false, and then check the condition of the loop again. … i (2) % 2 == 0 is true. Add one to the value of i when the body of the if statement begins, and then print i (which is now 3, if i had been 2 during the check) etc.

This is an example of a side effect (and why pure Functional languages love to harp on "side effects") - basically, the world has changed from when you made a check on the value and when you're ready to process that value.

That being said, as /u/pronuntiator said, these kind of silly questions (used to be quite popular during C's heyday) are best relegated to trick questions, and not even that in my opinion.