This is actually a thing in Rust too.
Just that in Rust it is actually being used.
The best example is breaking out of nested loops:
#![allow(unreachable_code)]fnmain(){'outer:loop{println!("Entered the outer loop");'inner:loop{println!("Entered the inner loop");// This would break only the inner loop//break;// This breaks the outer loopbreak'outer;}println!("This point will never be reached");}println!("Exited the outer loop");}
Edit: Imagine for example a "mainloop". Usually it's a while running where running is a global mutable variable or something.
In Rust you don't need that condition, you can just break out of the outer loop.
Edit 2: This is especially useful since blocks in Rust can return a value. This way you can use a loop and break out of it with a value.
This is comparable to inlining a function that contains a loop and returns.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is actually a thing in Rust too.
Just that in Rust it is actually being used.
The best example is breaking out of nested loops:
(taken from rustbyexample.com)
Edit: Imagine for example a "mainloop". Usually it's a
while running
where running is a global mutable variable or something.In Rust you don't need that condition, you can just break out of the outer loop.
Edit 2: This is especially useful since blocks in Rust can return a value. This way you can use a
loop
and break out of it with a value.This is comparable to inlining a function that contains a loop and returns.