History of Idiom 42 > diff from v21 to v22
Edit summary for version 22 :
↷
Version 21
2015-09-05, 09:13:23
Version 22
2015-10-29, 14:05:14
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.
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.
Code
sequence_ [ print v | v <- a, [ u | u <- b, u == v] == [] ]
Code
sequence_ [ print v | v <- a, [ u | u <- b, u == v] == [] ]
Comments bubble
Comments bubble
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 [].
Imports
import std.stdio;
Imports
import std.stdio;
Code
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); } }
Code
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); } }
Code
'outer: for va in &a { for vb in &b { if va == vb { continue 'outer; } } println!("{}", va); }
Code
'outer: for va in &a { for vb in &b { if va == vb { continue 'outer; } } println!("{}", va); }
Comments bubble
'outer is a label used to refer to the outer loop. Labels in Rust start with a '.
Comments bubble
'outer is a label used to refer to the outer loop. Labels in Rust start with a '.
Code
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"); }
Code
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"); }
Code
mainloop: for _, v := range a { for _, w := range b { if v == w { continue mainloop } } fmt.Println(v) }
Code
mainloop: for _, v := range a { for _, w := range b { if v == w { continue mainloop } } fmt.Println(v) }
Comments bubble
mainloop is a label used to refer to the outer loop.
Comments bubble
mainloop is a label used to refer to the outer loop.
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 [].