2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2016-10-29 22:54:04 +01:00
|
|
|
let x = vec![1, 2, 3];
|
2015-01-25 22:05:03 +01:00
|
|
|
let mut y = 0;
|
2015-01-31 12:20:46 -05:00
|
|
|
for i in &x { println!("{}", *i); y += *i; }
|
2014-10-14 21:07:11 -04:00
|
|
|
println!("{}", y);
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(y, 6);
|
2014-05-25 03:10:11 -07:00
|
|
|
let s = "hello there".to_string();
|
2015-03-25 17:06:52 -07:00
|
|
|
let mut i: isize = 0;
|
2015-01-26 21:21:15 -05:00
|
|
|
for c in s.bytes() {
|
2015-06-07 21:00:38 +03:00
|
|
|
if i == 0 { assert_eq!(c, 'h' as u8); }
|
|
|
|
if i == 1 { assert_eq!(c, 'e' as u8); }
|
|
|
|
if i == 2 { assert_eq!(c, 'l' as u8); }
|
|
|
|
if i == 3 { assert_eq!(c, 'l' as u8); }
|
|
|
|
if i == 4 { assert_eq!(c, 'o' as u8); }
|
2011-06-15 11:19:50 -07:00
|
|
|
// ...
|
2010-06-23 21:03:09 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
i += 1;
|
2014-10-14 21:07:11 -04:00
|
|
|
println!("{}", i);
|
|
|
|
println!("{}", c);
|
2010-06-23 21:03:09 -07:00
|
|
|
}
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(i, 11);
|
2011-08-15 21:54:52 -07:00
|
|
|
}
|