MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/gvf0dp/return_2/ftmtsw2/?context=3
r/badcode • u/[deleted] • Jun 02 '20
29 comments sorted by
View all comments
Show parent comments
10
I think it's this:
incrementByOne is equal to zero in its definition.
Then it gets incremented up by one.
Then it gets incremented up by one again.
incrementByOne is 2 right now. In the same statement, it's returned.
so this would be equivalent to "return 2;"
2 u/TheEnderChipmunk Jun 10 '20 Does the first increment not need to be assigned to the variable? I'm pretty sure it does 2 u/RovingRaft Jun 10 '20 what do you mean? 3 u/TheEnderChipmunk Jun 10 '20 Whoops I was being small brain. I thought x++ meant x+1 and not x += 1. Of course, with the actual name of the variable, not x. 1 u/RovingRaft Jun 10 '20 Ah, brain fart :Phappens to the best of usin any case, the code the guy made as a joke is identical to the one in the postjust that the variable starts at 0, instead of 1.
2
Does the first increment not need to be assigned to the variable? I'm pretty sure it does
2 u/RovingRaft Jun 10 '20 what do you mean? 3 u/TheEnderChipmunk Jun 10 '20 Whoops I was being small brain. I thought x++ meant x+1 and not x += 1. Of course, with the actual name of the variable, not x. 1 u/RovingRaft Jun 10 '20 Ah, brain fart :Phappens to the best of usin any case, the code the guy made as a joke is identical to the one in the postjust that the variable starts at 0, instead of 1.
what do you mean?
3 u/TheEnderChipmunk Jun 10 '20 Whoops I was being small brain. I thought x++ meant x+1 and not x += 1. Of course, with the actual name of the variable, not x. 1 u/RovingRaft Jun 10 '20 Ah, brain fart :Phappens to the best of usin any case, the code the guy made as a joke is identical to the one in the postjust that the variable starts at 0, instead of 1.
3
Whoops I was being small brain. I thought x++ meant x+1 and not x += 1. Of course, with the actual name of the variable, not x.
1 u/RovingRaft Jun 10 '20 Ah, brain fart :Phappens to the best of usin any case, the code the guy made as a joke is identical to the one in the postjust that the variable starts at 0, instead of 1.
1
Ah, brain fart :P
happens to the best of us
in any case, the code the guy made as a joke is identical to the one in the post
just that the variable starts at 0, instead of 1.
10
u/RovingRaft Jun 10 '20
I think it's this:
incrementByOne is equal to zero in its definition.
Then it gets incremented up by one.
Then it gets incremented up by one again.
incrementByOne is 2 right now. In the same statement, it's returned.
so this would be equivalent to "return 2;"