Daniel Rich wrote:This seems to be my pickle. I know that if i++ doesn't work i+1 will, however I don't understand why when it says they are the same thing just short hand. This seems a very small detail, but one thing that has been consistent in everything I've read is that making sure to understand these small things will help later.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Daniel Rich wrote:Thanks for the speedy reply.
I did as you said and I understand. Each cycle around the loop 1 gets added to the value of i however many times the value of lotto.length.
So, my understanding of i++ is simple short hand for saying add the value 1 to whatever is currently in i. i+1 is doing the same thing adding the value of 1 ontop of whatever the current value is.
This seems to be my pickle. I know that if i++ doesn't work i+1 will, however I don't understand why when it says they are the same thing just short hand. This seems a very small detail, but one thing that has been consistent in everything I've read is that making sure to understand these small things will help later.
Again, thanks so much for your help, really am grateful for the help.
Dan.
Daniel Rich wrote:I don't understand why when it says they are the same thing just short hand.
Red Smith wrote:
I believe that i++ is shortand for
i = i + 1
But more correctly, it is short hand for - temporarily store the value of i, then add 1 to i and store the result back in i, then return the pre-increment saved value of i.
Or another way to say it could be - return the value of i, then increment the value of i and store it in i.
++i is shorthand for - add 1 to i and store the result in i, then return the value of i
Daniel Rich wrote:I know this was a really 'noob' question, but it makes perfect sense now. Thanks.
Paul Witten wrote:
Did anybody point out that you were just trying to use an incrementer (i++) operator in place of a value (i)? Incrementers have no value.
Jeff Verdegan wrote:
Red Smith wrote:
I believe that i++ is shortand for
i = i + 1
It's not, though the difference between that and what it actually does is not always visible.
Or another way to say it could be - return the value of i, then increment the value of i and store it in i.
No, that's not the same, and it's not correct. Although I don't think it would ever make a difference in a correctly written program.
Jeff Verdegan wrote:
Paul Witten wrote:
Did anybody point out that you were just trying to use an incrementer (i++) operator in place of a value (i)? Incrementers have no value.
No, the expressions i++, ++i, i--, and --i each has a value. They are, respectively, the value of i before it gets incremented, the value of i after it gets incremented, the value of i before it gets decremented, and the value of i after it gets decremented. If they didn't have a value, you couldn't do this:
Red Smith wrote:
Jeff Verdegan wrote:
Red Smith wrote:
I believe that i++ is shortand for
i = i + 1
It's not, though the difference between that and what it actually does is not always visible.
What does it actually do?
Or another way to say it could be - return the value of i, then increment the value of i and store it in i.
No, that's not the same, and it's not correct. Although I don't think it would ever make a difference in a correctly written program.
Or another way to say it could be - return the value of i, then increment the value of i and store it in i.
No, that's not the same, and it's not correct. Although I don't think it would ever make a difference in a correctly written program.
What is the correct answer?
The correct answer is above.
Red Smith wrote:
You are a puzzle. Your greater than 4,000 posts seems to point to a person who likes answering Java questions. But from the answers you give, it would appear that you you don't like answering Java questions.
Red Smith wrote:
You are a puzzle. Your greater than 4,000 posts seems to point to a person who likes answering Java questions. But from the answers you give, it would appear that you you don't like answering Java questions.
Henry Wong wrote:
EDIT... BTW, in reading this topic over again -- I believe that both Red and Jeff has the same and correct understanding of the issue. The debate is simply over the analogy that was used to explain it.
Paul Witten wrote:If I may:...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Paul.
Please don't put enormously long lines inside code tags.
Jeff Verdegan wrote:I think it's better to learn the precise rule the hard way now than to learn "close enough" now and then have to unlearn it later.
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|