In [ ]:
:timing
:sccache 1
loop¶
In [12]:
let mut count = 0;
loop {
println!("{}", count);
count += 1;
if count >= 5 {
break;
}
}
Out[12]:
while loop¶
In [10]:
let mut count = 0;
while count < 5 {
println!("{}", count);
count += 1;
}
Out[10]:
In [11]:
let mut count = 0;
while true {
println!("{}", count);
count += 1;
if count >= 5 {
break;
}
}
Out[11]:
for loop¶
In [6]:
for word in "how are you".split_whitespace() {
println!("{}", word);
}
Out[6]:
In [5]:
for i in 1..5 {
println!("{}", i);
}
Out[5]:
In [4]:
fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}
In [4]:
let names: Vec<&str> = vec!["Pascal", "Elvira", "Dominic", "Christoph"];
for name in names {
println!("{}", name);
}
Out[4]:
In [6]:
let names = vec!["Pascal", "Elvira", "Dominic", "Christoph"];
for name in &names {
println!("{}", name);
print_type_of(name);
}
Out[6]: