Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

variable of interest  RSS feed

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted this code before but I must admit I still don't quite get it. What is the count variable counting when it prints out 4? I can see that there 4 array objects. Is that it?

 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no count variable, only an index. It's printing an element from the arrays.
 
Marcus Deviln
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so if it's printing an element from the array then it must be the '4' in the middle array correct? That's index [1][2] (index from zero), no?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the only 4 I see, yeah.
 
Sheriff
Posts: 21256
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Marcus Deviln wrote:so if it's printing an element from the array then it must be the '4' in the middle array correct? That's index [1][2] (index from zero), no?


Right. The reason is the initial value of index (1) and the post-increment in the indexing.

In short, what happens is this:
- the value of index is retrieved, 1
- index is increased to 2
- dd[1] is evaluated
- the value of index is retrieved, 2
- index is increased to 3
- dd[1][2] is evaluated
 
Danger, 10,000 volts, very electic .... tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!