Le 10/08/2013 15:10, Simon Sapin a écrit :
Proposal:

      for i in iter {
          // ...
      } else {
          // ...
      }

The optional else block is executed when the for loop stops without
exhausting the iterator, ie. when "break" is used.


Typical usage is finding an element in a container and have a default/fallback:

for element is container.iter() {
    if is_relevant(element) {
        do_something_with(element);
        break
    }
} else {
    not_found()
}

--
Simon Sapin
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to