user1656546
user1656546

Reputation: 93

Return to first Loop

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

Answers (2)

Bharat
Bharat

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

Daniel Fischer
Daniel Fischer

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

Related Questions