This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable of interest

 
Marcus Deviln
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?

 
David Newton
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic