• Post Reply Bookmark Topic Watch Topic
  • New Topic

For Loop didn't change value

 
Tom Hat
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I like to list all pdf files of the mentioned directory, but I only get all time the first pdf file...Where is my error? I really don't get it...
Thank you!

 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is there a return statement?

The return will exit the for loop and the method.
 
Tom Hat
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Why is there a return statement?

The return will exit the for loop and the method.


Oh sry my fault. But anyway, if I delete the return the situation didn't change.
If I put the while statement before the for the thread will completely pass. Then I'm not able to stop where I want but rather wait until the whole thread is passed...
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the purpose of the while statement again? I noticed the condition is always true for the while loop.

Try commenting out the while statement (not the loop) and see if the filename output changes. If that works, then its the while statement. You may also want to comment out the sleep part for this test.
 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you properly indented your code it would make it a lot easier to see what the code is doing.
The line that prints out the file name is in the while loop so if CopyOfSettingsGui.this.running is true it will repeatedly print the same file name until it is no longer true and then won't print anymore file names until it is true again.
You also have the potential problem of different threads accessing and changing CopyOfSettingsGui.this.running (assuming another thread changes it's value whilst this code is running) so unless 'running' is declared as volitile changes made by one thread may not be picked up by the other thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!