Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Need definition for line of code please?

Hi

I need to know what this line of code means:

for(String fn : files)

System.out.println("found " + fn);

Could you please tell me what the "fn" function is for and why it is being used in this line of code?

Thank you very much

God Bless

4 Answers

Relevance
  • Anonymous
    9 years ago
    Favorite Answer

    What is happening here is its taking all the variables in 'files' and putting them through a loop. Each loop iteration it puts the current element of files into 'fn' so 'fn' can be called to do something with it. This is how the new c++ 'for each' loops work. If you want more information look up for each loops in something like c#

  • 9 years ago

    fn is not a function, it's a variable that is being used to step thru a collection of strings named files. The code can be thought of as "Get each string from collection files sequentially, naming each occurrence fn and print it out."

  • 9 years ago

    fn appears to be a variable

  • 9 years ago

    for(int i = 0; i < files.size(); i++)

    System.out.println("found " + files.get[i]);

Still have questions? Get your answers by asking now.