Remaining flow control in RBE

This commit is contained in:
Dan Buch 2023-09-30 19:51:09 -04:00
parent dacbddca6e
commit b94fb3b31e
Signed by: meatballhat
GPG Key ID: A12F782281063434
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,16 @@
use std::str::FromStr;
fn get_count_item(s: &str) -> (u64, &str) {
let mut it = s.split(' ');
let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
panic!("Can't segment count item pair: '{s}'");
};
let Ok(count) = u64::from_str(count_str) else {
panic!("Can't parse integer: '{count_str}'");
};
(count, item)
}
fn main() {
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
}

View File

@ -0,0 +1,13 @@
fn main() {
let mut optional = Some(0);
while let Some(i) = optional {
if i > 9 {
println!("Greater than 9, quit!");
optional = None;
} else {
println!("`i` is `{:?}`. Try again.", i);
optional = Some(i + 1);
}
}
}