1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
11 fn calc_idx(i: usize) -> usize {
16 let ns = vec![2, 3, 5, 7];
19 println!("{}", ns[i]);
23 println!("{}", ns[i % 4]);
27 println!("{}", ns[i % ns.len()]);
31 println!("{}", ns[calc_idx(i)]);
35 println!("{}", ns[calc_idx(i) % 4]);
38 let mut ms = vec![1, 2, 3, 4, 5, 6];
39 for i in 0..ms.len() {
42 assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
44 let mut ms = vec![1, 2, 3, 4, 5, 6];
45 for i in 0..ms.len() {
49 assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
51 let g = vec![1, 2, 3, 4, 5, 6];
54 let x: u32 = g[i+1..].iter().sum();
55 println!("{}", g[i] + x);
57 assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
59 let mut g = vec![1, 2, 3, 4, 5, 6];
62 g[i] = g[i+1..].iter().sum();
64 assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
67 let mut vec = vec![0; 9];
74 let mut vec = vec![0; 10];
83 println!("{}", arr[i]);
87 println!("{}", arr[i]);
91 println!("{}", arr[i]);