Programming-Idioms

History of Idiom 42 > diff from v28 to v29

Edit summary for version 29 :
New C implementation by user [Dodopod]

Version 28

2017-04-13, 12:08:50

Version 29

2017-06-05, 15:53:59

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

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
Code
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;
}
Comments bubble
N is the length of a.
M is the length of b.

Using goto is usually considered bad practice in C.