This language bar is your friend. Select your favorite languages!

Idiom #42 Continue outer loop

Print each item v of list a which in not contained in list b.
For this, write an outer loop to iterate on a and an inner loop to iterate on b.

Illustration
int[] alist = {1,2,3,4,5};
int[] blist = {3,4};
int gb = 0;
foreach (int a in alist)
{
  foreach (int b in blist)
  {
    gb = b;
    if (b == a)
      break;
  }
  if (gb == a)
    continue;
  System.Console.WriteLine(a);
}
int *v = a;
while (v < a+N)
{
    int *w = b;
    while (w < b+M)
    {
        if (*v == *w)
            goto OUTER;
        
        ++w;
    }
    printf("%d\n", *v);
    
    OUTER: ++v;
}
#include <iostream>
auto a = {1,2,3,4,5};
auto b = {3,5};

for (auto va: a){
    for (auto vb: b){
        if (va==vb) goto OUTER;
    }
    std::cout << va << '\n';
    OUTER: continue;
}
import std.stdio;
auto a = [1,2,3,4,5];
auto b = [3,5];

void main()
{
mainloop:
	foreach(v;  a){
		foreach(w; b){
			if(v == w) continue mainloop;
		}
		writeln(v);		 
	}
}
main()  {
  var a = [1, 2, 3];
  var b = [2, 3];

  outer: for (var v in a) {
    for (var w in b) {
      if (w == v) continue outer;
    }
    print(v);
  }
}
  outer: do i=1,size(a)
     do j=1,size(b)
        if (a(i) == b(j)) cycle outer
     end do
     print *,a(i)
  end do outer
mainloop:
	for _, v := range a {
		for _, w := range b {
			if v == w {
				continue mainloop
			}
		}
		fmt.Println(v)
	}
sequence_ [ print v | v <- a, [ u | u <- b, u == v] == [] ]
OUTER:
for (var i in a) {
   for (var j in b) {
      continue OUTER if a[i] === b[j];
   }
   console.log(a[i] + " not in the list");
}
mainloop: for(int v:a){
	for(int w:b){
		if(v==w)
			continue mainloop;
	}
	System.out.println(v);
}
$array_1 = [1,2,3,4,5];
$array_2 = [3,4];

foreach ($array_1 as $a) {
    foreach ($array_2 as $b) {
        if ($b == $a) {
            continue 2;
        }
    }
    echo $a
}
  for v in a do
    begin
      for  w in b do
        if (v = w) then
          break;
      if (v = w) then
        Continue;
      writeln(v);
    end;              
OUTER:
for my $v (@a) {
   for my $check (@b) {
      next OUTER if $v == $check;
   }
   print "$v not in the list\n";
}
      
for v in a:
    try:
        for u in b:
            if v == u:
                raise Exception()
        print(v)
    except Exception:
        continue
a.each do |v|
  catch :matched do
    b.each do |u|
      throw :matched if v == u
    end
    puts v
  end  
end
'outer: for va in &a {
    for vb in &b {
        if va == vb {
            continue 'outer;
        }
    }
    println!("{}", va);
}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms