My question is this:
How do the 'for' statements know to what is the correct number to stop on for the statement to be correct? Is the 'if' statement directly below controlling it?
edit: I figured I might as well state that I just started learning Java (and programming) about 2 weeks ago. This is not an excuse for blatantly plagerizing someone else's code.
Riley Redd wrote:I am currently going through the book Absolute Java, 5/E and when I reached this problem...
Erm....what problem? I'm not familiar with the book, and you've plonked a bunch of code in front of us (which I've broken up a bit; please DontWriteLongLines).
I have no problem reverse-engineering stuff, but I'm usually paid big bucks to do it; and I'm also usually given at least a hint as to what it's supposed to be doing.
So - you want me to work for free? You'll need to provide a LOT more information than you have (lazy Riley?).
I assumed something like this would just do a permanent loop, yet it doesn't.
Edit: The program works like it is supposed to, I am just trying to understand the usage of the 'for' loop so that I may use it better in the future.
Bear Bibeault wrote:The second clause of the for statement sets the termination. For example, letterT < 10 loops while the value of letterT is less than 10 (but not equal to 10, note carefully).
Of course, if the code ever hits System.exit() everything comes to a crashing halt immediately.
I have to be completely honest...the bolded section went completely over my head.
edit: I don't even know what the first clause is ^.^'
1st clause: letterT = 0 initializes the iterator
2nd clause: letterT < 10 sets the condition for loop continuance (the loop will continue while the condition is true)
3rd clause: letterT++ updates iterator on every iteration
See: The for Statement
Riley Redd wrote:like it does in this program
Er...is there there something that wasn't clear about "please DontWriteLongLines"?
It's just that I notice that you've now edited your post a further 9 times, lengthening
virtually every line, to make the thread just as unreadable now as it was to start with.