Expressions and starting flow control in RBE
This commit is contained in:
18
rustbyexample/flow_control.d/loop.d/nested.rs
Normal file
18
rustbyexample/flow_control.d/loop.d/nested.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
#![allow(unreachable_code)]
|
||||
#![allow(unused_labels)]
|
||||
|
||||
fn main() {
|
||||
'outer: loop {
|
||||
println!("Entered the outer loop");
|
||||
|
||||
'inner: loop {
|
||||
println!("Entered the inner loop");
|
||||
|
||||
break 'outer;
|
||||
}
|
||||
|
||||
println!("This point will never be reached");
|
||||
}
|
||||
|
||||
println!("Exited the outer loop");
|
||||
}
|
13
rustbyexample/flow_control.d/loop.d/return.rs
Normal file
13
rustbyexample/flow_control.d/loop.d/return.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
fn main() {
|
||||
let mut counter = 0;
|
||||
|
||||
let result = loop {
|
||||
counter += 1;
|
||||
|
||||
if counter == 10 {
|
||||
break counter * 2;
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(result, 20);
|
||||
}
|
Reference in New Issue
Block a user