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.
10 fn calc_idx(i: usize) -> usize {
15 let ns = vec![2, 3, 5, 7];
18 println!("{}", ns[i]);
22 println!("{}", ns[i % 4]);
26 println!("{}", ns[i % ns.len()]);
30 println!("{}", ns[calc_idx(i)]);
34 println!("{}", ns[calc_idx(i) % 4]);
37 let mut ms = vec![1, 2, 3, 4, 5, 6];
38 for i in 0..ms.len() {
41 assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
43 let mut ms = vec![1, 2, 3, 4, 5, 6];
44 for i in 0..ms.len() {
48 assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]);
50 let g = vec![1, 2, 3, 4, 5, 6];
53 let x: u32 = g[i + 1..].iter().sum();
54 println!("{}", g[i] + x);
56 assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
58 let mut g = vec![1, 2, 3, 4, 5, 6];
61 g[i] = g[i + 1..].iter().sum();
63 assert_eq!(g, vec![20, 18, 15, 11, 6, 0]);
66 let mut vec = vec![0; 9];
73 let mut vec = vec![0; 10];
82 println!("{}", arr[i]);
86 println!("{}", arr[i]);
90 println!("{}", arr[i]);