RosettaCodeData/Task/Loops-Nested/Rust/loops-nested.rust

23 lines
445 B
Text
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
use rand::Rng;
2014-01-17 05:32:22 +00:00
2015-11-18 06:14:39 +00:00
extern crate rand;
2014-01-17 05:32:22 +00:00
fn main() {
2015-11-18 06:14:39 +00:00
let mut matrix = [[0u8; 10]; 10];
let mut rng = rand::thread_rng();
2014-01-17 05:32:22 +00:00
2015-11-18 06:14:39 +00:00
for row in matrix.iter_mut() {
for item in row.iter_mut() {
*item = rng.gen_range(0, 21);
2014-01-17 05:32:22 +00:00
}
}
2015-11-18 06:14:39 +00:00
'outer: for row in matrix.iter() {
2014-01-17 05:32:22 +00:00
for &item in row.iter() {
print!("{:2} ", item);
2015-11-18 06:14:39 +00:00
if item == 20 { break 'outer }
2014-01-17 05:32:22 +00:00
}
2019-09-12 10:33:56 -07:00
println!();
2014-01-17 05:32:22 +00:00
}
}