Reputation: 93
for(Integer i : list1)
for(Integer x : list2)
if(i.equals(x))
continue;
all i want to do, is when i.equals(x), cancel second loop(for(Integer x : list2)) and continue with next element of list1.
Upvotes: 0
Views: 662
Reputation: 100
Putting a 'break' solves your problem. If you want to use 'continue' you can do that by labeling the first for loop
MAIN: for(Integer i : list1)
for(Integer x : list2)
if(i.equals(x))
continue MAIN;
Check this link for more info http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
Upvotes: 2
Reputation: 183878
Then you should use break
instead of continue
. break
ends the execution of the innermost enclosing loop, exactly what you want.
Upvotes: 6