summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch2/ch2-3arrays.rs
blob: 58d0ff2b73e07128484e5fd7ce65ca6a35be532a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
  let one            = [1,2,3]; // <1>
  let two: [u8; 3]   = [1,2,3]; // <2>
  let blank1         = [0; 3]; // <3>
  let blank2: [u8; 3] = [0; 3]; // <4>

  let arrays = [one, two, blank1, blank2]; // <5>

  for a in &arrays { // <6>
    print!("{:?}: ", a);
    for n in a.iter() { // <7>
      print!("\t{} + 10 = {}", n, n+10);
    }

    let mut sum = 0;
    for i in 0..a.len() {
      sum += a[i];
    }
    print!("\t(Σ{:?} = {})", a, sum);
    println!("");
  }
}