This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Something wrong with this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Something wrong with this" Watch "Something wrong with this" New topic

Something wrong with this

Ken Whitestone

Joined: Jul 22, 2013
Posts: 15
I'm having trouble with the following code:

For some strange reason, once the expression is no longer true, instead of printing a new line, then resetting the count and continuing with the remaining iterations of the loop, it continues adding 1 to the count throughout the remaining iterations of the loop, but doesn't print "args[i] ". What am I missing?
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10433

Notice that if your "if" block doesn't (intentionally or unintentionally) use a "{" to enclose the if block then only the next statement following the if statement is considered to be part of that if block. I'll just add some blank lines in your code to give you an picture on what's wrong:

See what the problem is?

[My Blog] [JavaRanch Journal]
Ken Whitestone

Joined: Jul 22, 2013
Posts: 15
Yes, thank you. I knew there was something wrong because it wouldn't let me add an "else" to that "if" statement, which is what I really needed to begin with. Problem solved.
I agree. Here's the link:
subject: Something wrong with this
It's not a secret anymore!