Computer Science, asked by shamilayyoob8983, 1 year ago

Var x = 1; for (var i = 0; i < 3; i++) { x += 5 * i; } console.log(x); what does this print?

Answers

Answered by aqibkincsem
0
This prints the number '16' to the console. The value of x is originally 1. The for-loop executes 3 times total. First execution, x remains 1 because i equals 0. The second execution updates the value of x to 6, because 5 * 1 equals 5 and that value gets added to x, making it now 6. The third and final execution updates the value of x to 16 because 5 * 2 equals 10, and this gets added to the value of x which is 6. The value of x is now 16, and i gets updated to the value of 3. Now that i equals 3, it fails the condition in the for loop that i < 3, so the program moves to the next line which simply prints the value of x. This value is 16, so that is what gets printed.
Similar questions