The straightforward solution is to put the entire search process in a method and return as soon as you have an answer.
However, the abstract form of your sample code leaves some other possibilities in question. For instance, is there a way to "index" some of the content (e.g. using Map instances) so that you don't have to use brute-force loops?