0
Hello everyone. I need your help. How is it possible that output of this code is 2.
3 Answers
+ 3
What would you have expected instead? In the first iteration, i = 1, so neither i < 1 nor i > 1 are true. Therefore, the condition false || false is false and the loop goes on. During the second iteration however, i = 2, so i > 1 is now true. Since the logical OR is true if at least one operand is true, the condition is true as well and we print the value of i, which is 2.
+ 1
because the check is, "if i is less than 1 or greater than 1...".
The first iteration, i is equal to 1 so nothing happens. Then i is incremented by 1.
Then it's checked again, since i is now equal to 2, the check triggers and prints i's value, wich is 2.
+ 1
Thank you guys for your help. I was considering i<=1 instead of i>=1 in the loop. The real crackhead is heređ