This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
This one is easy. since x is declared inside the "for" statment, it falls out of scope once you leave the loop. you don't have braces after your "for" statement so, the only line that is part of your loop is the "tempBuyCar" line. that is the ONLY line being run over and over.
when you get to the arrayOfCars, x has fallen out of scope, thus the compiler can't resolve it.
and life should be good. [ May 20, 2004: Message edited by: fred rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: May 20, 2004
yep that fixed it. can't believe how simple it was.
Some beginners, and some folks with a bit of experience, like myself, always include opening and closing braces, with constructs such as for-loops and if-statements.
It's also a required/recommended practice by some coding syle guides, such as JavaRanch's style guide. The reasoning for this is that consistency is easier to read, less editing is involved if lines of code are added or removed, plus it becomes very obvious what code is associated with the construct.
Also, I strongly recommend that you make a practice of properly indenting your code, as this will strongly help in its readability.