rustbites rustbites bite-sized rust tips
Archives About
#005 Jan 25, 2022
loop break

5. Loop breaks and labels

Breaks and labels in loops?

IT is possible to use a label to specify which enclosing loop is affected.

1
2
3
4
5
6
7
8
let s = 'outer: loop {
      for idx in 0..10 {
          if idx == 4 {
              break 'outer idx;
          }
      }
  };
assert!(s == 4);

This post is licensed under CC BY 4.0 by the author.

Share:
← Previous 4. Option -> Result Next → 6. non-exhaustive enums

Trending Tags

Rust Iterator Option Iter Iterators Result Collections Enum Macro Match Std Vec Array-Windows Arrays Async Attributes Break Closure Closures Combinators Compiler Concurrency Cow Debugging Default Drain Entry Enumerate Error-Handling Filter Flatten Fn Fnmut Fnonce Fold From_fn Functional Hashmap If-Let Initialization Lazy Lazylock Loop Map Matching Mem Ownership Pattern-Matching Performance Pettern Position Raw String Scan Scoped-Threads Slices Smart-Pointers Static Stdlib String Strings Threads Tokio Trait-Objects Traits Upcasting

Recently updated

#043 43. Vec::extract_if — Remove Elements and Keep Them #042 42. array::from_fn — Build Arrays from a Function #041 41. Async Closures — Pass Async Code Like Any Other Closure #040 40. Scoped Threads — Borrow Across Threads Without Arc #039 39. Trait Upcasting — Cast dyn Trait to dyn Supertrait

About

A collection of bite-sized Rust tips and tricks. Small, focused lessons to help you write better Rust.

info@rustbites.com
rustbites rustbites · 2022—2026
X RSS

This site uses cookies for analytics and ads. Learn more