This is a Java/Groovy question, im doing this function to implement in a search mechanism in my website. I have two lists:
String [] lista = temp.split() // ignore the temp part
String [] searchLista = search.split() // ignore the search part
Basically, the lists are something like this:
lista = {a, b, c, d}
searchLista= {a, b, a, d}
boolean test
I want to verify if, any element on list ‘lista’ is the same on ‘searchLista’. For that i did the following function:
for(int i = 0; i< lista.length-1; i++){
for(int j = 0; j< searchLista.length-1; j++) {
if(lista[i].contains(searchLista[j])){
test = true
##
}
}
}
My question is, if this validation is true: ‘lista[i].contains(searchLista[j])’, boolean variable test becomes true and next i want to jump outside both fors. A simple ‘break’ in the place of the ##s will do it?
(Are you deliberately missing out the last element of both lists, by the way?)
A normal
breakstatement would just exit the inner loop.If you want to break two levels, there are three common options:
Example of the last option:
Personally I don’t use labels very often – I would rather use the “make the whole double loop a method” option if possible.