Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Something wrong with this

 
Ken Whitestone
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ken Whitestone
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic