Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
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);
}
}
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;
}
N is the length of a.
M is the length of b.
Using goto is usually considered bad practice in C.
M is the length of b.
Using goto is usually considered bad practice in C.
int gb = 0;
foreach (int v in a)
{
foreach (int w in b)
{
gb = w;
if (w == v)
break;
}
if (gb == v)
continue;
System.Console.WriteLine(v);
}
This borrows from the Pascal implementation.
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);
}
}
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)
}
mainloop is a label used to refer to the outer loop.
sequence_ [ print v | v <- a, [ u | u <- b, u == v] == [] ]
a _\\ b abbreviates this task if you are not required to write your own printing iterations
Our outer loop continues to the next element whenever the inner list equality test breaks the inner iteration lazily after the first of any [u|u==w] found growing too large to equal [].
Our outer loop continues to the next element whenever the inner list equality test breaks the inner iteration lazily after the first of any [u|u==w] found growing too large to equal [].
OUTER:
for (var i in a) {
for (var j in b) {
if (a[i] === b[j]) {
continue OUTER;
}
}
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);
}
mainloop is a label used to refer to the outer loop.
$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
}
The number next to the continue statement determines how many loops "up" it should skip. continue 1 is the same as continue with no numerical argument passed, and will skip to the next iteration of the current loop.
for v in a do
begin
for w in b do
if (v = w) then
break;
if (v = w) then
Continue;
writeln(v);
end;
You have to break the inner loop first, before you can continue the outer loop.
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
Note that using two loops like this in python is by itself very un-idiomatic. Also one would be wise to define a custom exception to avoid hiding "real" exceptions.
for v in a:
keep = True
for w in b:
if w == v:
keep = False
break
if keep:
print(v)
Using a boolean variable
z = False
for x in a:
for y in b:
if y == x:
z = True
break
if not z: print(x)
z = False
a.each do |v|
catch :matched do
b.each do |u|
throw :matched if v == u
end
puts v
end
end
Idiomatic ruby would be: puts a-b