how do i exit a for loop in an if else statement? groovy - java
<p>My code worked fine until I added the <code>else</code> block.</p>

<pre><code>String getInputSearch = JOptionPane.showInputDialog("city")

for(int i=0; i &lt; listArray.length; i++) {
    if(getInputSearch == loadData()[i][0]) {
        for(int j=0; j&lt; loadData()[i].length; j++) {
            println(loadData()[i][j])
        }
        println("")
    }
    else {
        println( getInputSearch+ "not a valid city");
    }
}
</code></pre>

<p>If I add a <code>break</code> within the <code>else</code> block, the loop only works once and if I don't it keeps printing "not a valid city," even if the city is valid until it reaches the the right index in the array. (data is read from a text file btw)
help would be appreciated. </p>