Return statement not working
<p>Can someone help me with fixing my problem. I have a function which checks if a file is present in a particular path. the function checks if the filenames match and also the paths also match.(A file with a particular name could be present in multiple locations). Please find below my code.</p>

<p>memberPath is a static variable which contains the relative path.
file_Path is a static variable which gets updated when the match has been found.</p>

<p>My problem is the function finds the match but it breaks out of the for-loop comes to return statement but goes back to the for loop. Can someone help me to fix my code so that once the match is found it returns bac to the calling position.</p>

<pre><code>public static String traverse(String path, String filename) {
        String filePath = null;
        File root = new File(path);
        File[] list = root.listFiles();

        for (File f : list) {
            if (f.isDirectory()) {
                traverse(f.getAbsolutePath(), filename);
            } else if (f.getName().equalsIgnoreCase(filename) &amp;&amp; f.getAbsolutePath().endsWith(memberPath)) {
                filePath = f.getAbsolutePath();
                file_Path = filePath;
                break ;
                }
        }
        return filePath;
}
</code></pre>
