Ok, lets say I have ten stones. In addition I have one pocket. I could easily write a program which lets me pick up stones, put them in a pocket, and take them out. In addition such a program could keep track of how many stones were in the pocket, and how many weren't.
But lets say I have two pockets, in that case I would have to do:
But what if, I had x pockets. It would be easy to write code which lets me change the number of stones in my system, a simpleCode:
would accomplish that, but what if I don't know the number of pockets? I could do:Code:
which although a tedious task, could be done...however, the problem with that method is that I am then left with using excessive memory, if i make my program capable of knowing the contents of 50 pockets then, if I only use 15 pockets, I am wasting memory remembering that 45 pockets aren't being used.Code:
What can I do? I suspect that objects are what I need to use but it seems every tutorial I find doesnt really address any of my questions, always focusing on some other aspect of the concept.
It would be beneficial if a group of users worked together to write tutorials, referring those who ask questions to the tutorials, and improving the tutorials over time.