Problem comparing arrays of Strings with nested loops
<p>This is the problem I am trying to solve: I have two arrays of Strings ("matches" and "visibleObjects"). I would like to search through all the words in the array "matches" to see if there is at least one word from the array "visibleObjects". If this condition is satisfied, I'd like to search through the words in "matches" again this time looking for at least a word from the array "actionWords". This is what I have, where "testDir" is just a debug string that gets printed:</p>

<pre><code>protected void Action(){
        boolean actionWord = false;
        String target = null;

        testDir = "first stage";
        firstLoop:
        for(String word : matches)
        {
            testDir += " " + word;
            for(String hint : visibleObjects)
            {
                testDir += " " + hint;
                if(word.equals(hint))
                {
                    target = word; //found a matching word
                    testDir = "Hint found";
                    break firstLoop;
                }
            }
        }

        if(target != null)
        {
            testDir = "stage two";

            secondLoop:
            for(String word : matches)
            {
                for(String action : actionWords)
                {
                    if(word.equals(action))
                    {
                        actionWord = true; //found one word from the actionWords array
                        testDir = "Acion OK";
                        break secondLoop;
                    }
                }
            }
        }


        if(actionWord){
            testDir = target;
            performAction(target);
        } 
    }
</code></pre>

<p>All I get printed is the first word from the array matches and all the words from the array visibleObject once, so it doesnt get past the second loop....</p>

<p>Is this code right? Can anyone spot the bug?</p>

<p>Thanks for your help!</p>
